Search code examples
javaexecutors

Executors threads not terminating


I am using Executors.newFixedThreadPool(100) method. Single command execution needs approx 20 threads. After executing the command 5-6 times, application stops responding. My thread is implementing Callable.

I doubt, that thread doesn't terminate after completion. I have also called shutdown() to terminate the thread.

Can anybody please tell, when I use get() method to retrieve the thread's result, does it gets terminated(means, its removed from the queue) or it is still there in the queue, which is used by pool to store the threads.


Solution

  • The threads don't terminate. What happens is this:

    • All worker threads wait for the input queue
    • One thread pops the head element from the queue
    • It runs the Callable
    • It pushes the result into the result queue
    • It waits for a new element in the input queue

    So either the result queue overflows or your Callable doesn't return.