We have a scenario where tasks submitted to ThreadPoolExecutor are long running. When the thread pool is started we start it with core pool size = 5, max pool size = 20 and queue size of 10. In our application around 10 tasks get submitted. Most of the time these tasks run for few mins/hrs and then complete. However there was a situation when all of the 5 tasks got hanged on I/O. As a result my core pool size reached it max, but my Threadpoolexecutor queue was not full. So the additional 5 tasks never got a chance to run. Please do suggest how we can handle such scenario? Is having a smaller queue better option in such situation? What would be an optimum queue size while initializing threadPool?
Also regarding the hanged tasks, is there any way we can pull out the threads out of the Threadpool? In that case at least other tasks would get a chance to run.
The overall situation is like this:
core pool size = 5,
max pool size = 20 and
queue size of 10
10 tasks are submitted. Out of which
Hence, Your Program is hanged .
To know more about dynamics of ThreadPoolExecutor
watch here . The notable points of this doc is as follows:
EDIT
If you wish to increase core pool size then you can use setCorePoolSize(int corePoolSize) . If you increase the corepoolsize
then new threads will, if needed, be started to execute any queued tasks.