I want to optimize my application number of threads. Almost all of them have IO beside CPU usage in an equal value. How much is the efficient number of threads when there ar
The Java Concurrency in Practice book gives a rough formula for sizing a thread pool to keep your CPUs pegged at a certain utilization:
N = number of CPUs
U = target CPU utilization, 0 <= U <= 1
W / C = ratio of wait time to compute time
The optimal pool size (number of threads) for keeping processors at the desired utilization is:
PoolSize = N * U * (1 + (W/C))
This is just for CPU utilization though.
You can get the available processors with Runtime.getRuntime().availableProcessors()