In our application, we have a lot of ThreadPoolExecutor
s. When the application is idle, the ThreadPoolExecutor
s are also idle, but the number of idle threads in the application is very high.
In the thread dump, I found out that most of the threads belong to the ThreadPoolExecutor
s waiting for tasks. Are there any side effects in keeping these worker threads alive? Should I use setAllowCoreThreadTimeOut()
in ThreadPoolExecutor
so that the worker threads die after being idle for sometime?
Every thread has an associated stack which requires some amount of memory (configurable). If your threads are in the waiting state (and even if they aren't), they are reserving that memory. It can't be used by the rest of your application. Therefore, it might make sense to stop those threads (with setAllowCoreThreadTimeout()
), release the memory they had reserved, and let the ThreadPoolExecutor
recreate them as needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With