Reputation: 90023
I understand why thread pool sizes are tied to the number of CPU cores, but why did the designers of ForkJoinThread
default to using # of cpu cores - 1
threads? Why the -1
?
If I am constructing my own ForkJoinPool
(not using the common instance), and the main
thread is blocked on the pool waiting for it to return some result, is there any reason I would want to allocate less than Runtime.getRuntime().availableProcessors()
threads?
UPDATE: Please explain why you are down-voting. Otherwise, I can't improve the question.
Upvotes: 1
Views: 1535
Reputation: 37
This makes sense. One thread is always required for the main thread and the max number of threads running at once is the total number of cores. Hence, the default parallelism being # of cpu cores - 1
.
Upvotes: 0
Reputation: 279970
There's a comment in the Oracle JDK implementation. It states
* When external threads submit to the common pool, they can
* perform subtask processing (see externalHelpComplete and
* related methods) upon joins. This caller-helps policy makes it
* sensible to set common pool parallelism level to one (or more)
* less than the total number of available cores, or even zero for
* pure caller-runs.
In other words, when external (not part of the FJP's threads) (can) help with the execution of tasks, additional threads aren't always beneficial.
Upvotes: 1