[英]Why doesn't the common ForkJoinPool try to use all cores?
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? 我知道为什么线程池大小与CPU内核数有关,但是为什么
ForkJoinThread
的设计人员默认使用# of cpu cores - 1
线程? Why the -1
? 为什么为
-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? 如果我正在构建自己的
ForkJoinPool
(不使用公共实例),并且main
线程在池中被阻塞,等待它返回一些结果,那么是否有任何我想分配小于Runtime.getRuntime().availableProcessors()
线程?
UPDATE : Please explain why you are down-voting. 更新 :请解释为什么您不赞成投票。 Otherwise, I can't improve the question.
否则,我无法改善这个问题。
There's a comment in the Oracle JDK implementation . Oracle JDK实现中有一条注释。 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. 换句话说,当外部(不是FJP线程的一部分)(可以)帮助执行任务时,附加线程并不总是有益的。
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
. 因此,默认并行度
# of cpu cores - 1
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.