newCachedThreadPool() versus newFixedThreadPool()
When should I use one or the other? Which strategy is better in terms of resource utilization?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I think the docs explain the difference and usage of these two functions pretty well:
newFixedThreadPoolnewCachedThreadPoolIn terms of resources, the
newFixedThreadPoolwill keep all the threads running until they are explicitly terminated. In thenewCachedThreadPoolThreads that have not been used for sixty seconds are terminated and removed from the cache.Given this, the resource consumption will depend very much in the situation. For instance, If you have a huge number of long running tasks I would suggest the
FixedThreadPool. As for theCachedThreadPool, the docs say that “These pools will typically improve the performance of programs that execute many short-lived asynchronous tasks”.