I'm working on some application and using ThreadPoolExecutor for handling various tasks. ThreadPoolExecutor is getting stuck after some duration. To simulate this in a simpler environment, I've written a simple code where I'm able to simulate the issue.
Try executing this code a few times. It normally print outs the number on console and when all threads end, it exists. But at times, it finished all task and then is not getting terminated. The thread dump is as follows:
In my actual application,ThreadPoolExecutor threads go in this state and then it stops responding.
PS: I'm new to JavaRanch. Please let me know if I've not followed any rules.
Peter Taucher wrote:I think you need to shutdown the pool sometime. Try adding this code at the end of your main method:
That seems unnecessarily complex - shutdown() will already wait until all current tasks are completed, so I'd just call it directly.
The problem is, it sounds like Ravi wants to keep this pool around awhile to await future tasks, and sometimes all the threads get suspended somehow.
I can't seem to recreate the problem on my machine using the code shown. I'm running a Mac, so the different JVM internals may be why I can't recreate it.
When I do a thread dump, I get virtually the same results as Ravi - with the critical difference that all his threads say "(Suspended)", while mine do not. So the question is, what causes the threads to become suspended?
One thing to try is to run this in an IDE, and set a break point on the suspend() method in the Thread class. If something in the system is calling suspend(), this should let you know what it is.
Anyone else got any ideas on what might cause the threads to become suspended?