Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Executors.newFixedThreadPool(10);

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 ?

like image 399
Jai Avatar asked May 06 '16 05:05

Jai


People also ask

What is ideal thread pool size?

So the ideal thread pool size is 4 cores * 2 * ( 1 + 9 ) = 80. If all 100ms are calculation, 0ms is waiting. the blocking coefficent is 0. The ideal thread pool size is 4 * 2 * 1 = 8.

What is the maximum size of thread pool?

Starting thread pool size is 1, core pool size is 5, max pool size is 10 and the queue is 100. As requests come in, threads will be created up to 5 and then tasks will be added to the queue until it reaches 100. When the queue is full new threads will be created up to maxPoolSize .

What is the default thread pool size in spring boot?

The default configuration is a core pool size of 1, with unlimited max pool size and unlimited queue capacity.


1 Answers

First of all,

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

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

3.) There might be a case, where you are allocating fewer threads than the server has, or might allocate more, and your tasks doe not require that many. It is more or less a waste 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.

For more, Java Concurrency in Practice has a detailed chapter on thread pools.

like image 153
Ankur Singhal Avatar answered Oct 09 '22 01:10

Ankur Singhal