0

I am developing a program that needs to spawn threads based on some inter arrival.

  • I have a control class that spawns a new thread every "interarrival", those threads are set to setDaemon(true).
  • Every thread stops itself after a "duration" time. (calculated locally in the thread).
  • I have implemented an ExecutorService with ExecutorService threadExecutor = Executors.newFixedThreadPool(250); to hold a reference of 250 threads and be able to stop all threads if needed.
  • This is in theory because after testing, only 47 threads are spawned.

So my questions are:

  • is there a limit in the ExecutorService? should I change to chached?
  • is this a limit of the JVM?
  • how can I pass this limit and spawn new threads keeping the "interarrival"?
  • is there a best approach to achieve this?
  • also is there a way to detect the number of threads I can spawn before JVM crashes?
3
  • 1
    You show no code, then ask several questions. Post some code than demonstrates the problem you are having, and I'm sure someone can help. Commented May 7, 2011 at 16:13
  • Better yet, could you post some context to the problem. The concurrency package is quite good at managing threads. I am concerned that you may be re-implementing something that is already done for you. Commented May 7, 2011 at 16:40
  • 1
    You haven't given us enough information, but I can tell you 47 is not the JVM limit.... Commented May 7, 2011 at 16:40

2 Answers 2

1

How do you know that only 47 are spawned? Why are you using an executor if you are spawning threads?

  • is there a limit in the ExecutorService? should I change to chached?

The limit is determined by the amount of memory, and the os. There isn't a fixed limitation.

  • is this a limit of the JVM?

No

  • how can I pass this limit and spawn new threads keeping the "interarrival"?

I don't understand that question.

  • is there a best approach to achieve this?

I haven't understood what you want to do, so I can unfortunately not answer that.

  • also is there a way to detect the number of threads I can spawn before JVM crashes?

No, because the number of threads that you can create can be affected by VM arguments. It will also depend on OS, memory etc.

Sign up to request clarification or add additional context in comments.

1 Comment

This program spawns threads that make a call in a time calculated from exponential distribution wich is my interarriaval. So every call has a target, and at the target I can see only 47 threads, and when one call ends the number of incoming calls increases. e.g. 47 active calls, if one call ends,total call number increases to 48. "Why are you using an executor if you are spawning threads?" Because of the amount of threads beeing spawned, I wanted something to hold all those threads, also because I want to have a reference to all active threads and be able to shut them down. regards maxsap
-1

I didn't thoroughly read through your code, though i think there is a possibility which the thread you spawned previously has finished running and died, as every call is the same length and the rate of generating new call is constant (depends on your profile.getCallInterarrival();). When your program first start, it would constantly generate new threads until 1 minute later (60000), calls starts to die, and the system will reach an equilibrium which every new call created, there is an call died.

If my theory is right, your profile.getCallInterarrival() will return something like 1.33.

1 Comment

You are correct getCallInterarril will return 0.33434 thats why i multiplu it then.havent tested your theory thought

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.