Number of Threads for an optimized thread pool
- $N_{cpu}$ = Number of Available CPUs
- $U_{cpu}$ = Target utilization of those CPUs (0 ⇐ $U_{cpu}$ ⇐ 1)
- $W_c$ = Ratio of Wait time / Compute time
Following the formula: $ N_{threads} = N_{cpu} * U_{cpu} * (1 - W_c)$
You can determine the number of CPUs using Runtime:
int N_CPUS = Runtime.getRuntime().availableProcessors();