Java – too many garbage collection threads
I'm using java to develop software that creates a thread when receiving events (from sensors) The lifetime of these threads is very short (< 1 second)
I don't know if the bug is caused by dynamic thread creation or other errors in my code?
Editor: the problem is really caused by creating too many threads I've time stamped all the sensor events, and it creates some points of about 1200 events / min (damn it!) I also wrote a small java program that created as many threads as possible At ~ 4100 threads (well, wooden computer), the JVM crashed It doesn't hang like my application: –? Therefore, I think there may be (possibly) rare situations when dynamically creating threads and cause the garbage collection thread to hang?
Solution
Do not create a new thread for each event received Instead, use Java util. Classes in the concurrent package
Create an executorservice (using a static method in the class executors) and submit the job to handle events to executorservice Executorservice is a thread pool that can manage threads for you