Jai Jai - 8 months ago 23
Java Question

What is ideal size of Fixed Thread pool?

Fixed Thread pool has been used to limit the number of threads in java application by passing an integer variable to the executors method like below


Now, Here comes a question. Suppose we are designing any application and we are using fixed thread pool then how can we take up a decision for an ideal fixed thread pool size or on what basis we should decide the fixed thread pool size ?


First of all,

1.) Are you creating FixedThreadPool for whole application or for specific task in your application.

2.) The server in which your application is deployed, supports how many CPU's, per CPU how many threads.

3.) There might be case, you are allocating less number of threads, whereas the server has more, or might allocate more, and your tasks does not require that many. It is more or less like wastage of resources.

Thread pool sizes should rarely be hard-coded; instead pool sizes should be provided by a configuration mechanism or computed dynamically by consulting Runtime.availableProcessors.

a good detailed understanding is available here