N
The Daily Insight

What should be the size of thread pool?

Author

Christopher Pierce

Updated on March 01, 2026

Ideally, there is no fixed number which is ideal to be used in deciding the number of threads pool. It all depends on the use-case of the java program. Therefore, there are two factors on which decision should be taken to decide the thread pool size.

How many CPU threads is too many?

If your thread usage peaks at 3, then 100 is too much. If it remains at 100 for most of the day, bump it up to 200 and see what happens. You could actually have your code itself monitor usage and adjust the configuration for the next time it starts but that’s probably overkill.

How do you find optimal number of threads?

I came up with a method to calculate the optimal number of threads by making two measurements of processing times Tn and Tm for two arbitrary number of threads ‘n’ and ‘m’. For linear algorithms, the optimal number of threads will be N = sqrt ( (mn(Tm*(n-1) – Tn*(m-1)))/(nTn-mTm) ) .

What is core pool size in ThreadPoolTaskExecutor?

The corePoolSize is the minimum number of workers to keep alive without timing out. It is a configurable property of ThreadPoolTaskExecutor. However, the ThreadPoolTaskExecutor abstraction delegates setting this value to the underlying java.

How do you calculate thread pool?

How to set an ideal thread pool size

  1. /** Thread Pool constructor */ public ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue workQueue) {…
  2. Number of threads = Number of Available Cores * (1 + Wait time / Service time)

What is Java thread pool?

Java Thread pool represents a group of worker threads that are waiting for the job and reused many times. In the case of a thread pool, a group of fixed-size threads is created. After completion of the job, the thread is contained in the thread pool again.

How many threads does a Core i7 have?

The new Core i7-9700K gets eight cores and eight threads.

How many threads can I run on 4 cores?

Each core can only run 1 thread at a time, i.e. hyperthreading is disabled. So, you can have a total maximum of 20 threads executing in parallel, one thread per CPU/core.

How many threads should a CPU have?

Each CPU core can have two threads. So a processor with two cores will have four threads. A processor with eight cores will have 16 threads. A processor with 24 cores (yes, those exist), will have 48 threads.

What is core pool size and max pool size?

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 core pool size in Java?

The corePoolSize is the minimum number of workers to keep alive without timing out. It is a configurable property of ThreadPoolTaskExecutor. However, the ThreadPoolTaskExecutor abstraction delegates setting this value to the underlying java. util. concurrent.

How to get the optimal size of a thread pool?

In case of multiple thread pools, just add a target CPU utilization parameter to the formula. Target CPU utilization [0..1], 1 – means thread pull will keep the processors fully utilized). At this step we can get an optimal thread pool size, we know our theoretical upper bounds and we have some metrics in place.

Does increasing the size of a thread pool reduce latency?

If we want to reduce latency, the elephant in the room is dead time and since we have loads of spare CPU it’s safe to increase the size of the pool to allow requests to get to it. Since our core count is four lets run the same experiment but with the thread pool size set to four.

How many threads can a CPU run at a time?

A typical desktop generally is a quad core which means there are four cores in a CPU. While a server or cloud can have as many as cores in CPU. So, if one core is there in CPU then we can run one thread at a time. It simply means more cores then more parallelism.

How to set the target CPU utilization for multiple thread pools?

In case of multiple thread pools, just add a target CPU utilization parameter to the formula. Target CPU utilization [0..1], 1 – means thread pull will keep the processors fully utilized).