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?