简体   繁体   English

常见的ForkJoinPool为什么不尝试使用所有内核?

[英]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.

相关问题 java中如何使用ForkJoinPool来使用多核? - How to use ForkJoinPool to use multiple cores in java? Java ForkJoinPool不使用所有CPU内核 - Java ForkJoinPool not utilising all CPU cores 为什么ForkJoinPool不运行所有任务? - Why is ForkJoinPool not running all tasks? 为什么ForkJoinPool使用ThreadPerTaskExecutor? - Why does ForkJoinPool use ThreadPerTaskExecutor? 为什么不使用所有处理器? - Why doesn't it use all of the processor? 为什么Spark Standalone集群不使用所有可用内核? - Why does Spark Standalone cluster not use all available cores? 如何在ForkJoinPool中使用MDC? - How to use MDC with ForkJoinPool? CompletableFuture 没有被执行。 如果我使用 ExecutorService 池,它可以按预期工作,但不能使用常见的 ForkJoinPool - CompletableFuture is not getting executed. If I use the ExecutorService pool it works as expected but not with the common ForkJoinPool 如何在Solrj中使用Solr的所有核心 - How to use all the cores of Solr in solrj 我的Eclipse中的Java代码似乎可以运行,但是MySQL为什么不将其插入表中? 我们可以使用两个try catch吗? - My java Code in Eclipse seems to run but MySQL doesn't insert it into the table why? Can we use two try catch?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM