简体   繁体   中英

Why does CompletableFuture.runAsync() not always submit to ForkJoinPool.commonPool()?

CompletableFuture.runAsync documentation states:

Returns a new CompletableFuture that is asynchronously completed by a task running in the ForkJoinPool.commonPool() after it runs the given action.

However, as far as I can tell, runAsync only submits a task to ForkJoinPool.commonPool() when ForkJoinPool.getCommonPoolParallelism() > 1 . If not, it manually creates a new Thread for each submitted task.

Why exactly is this the case?

Yes, if ForkJoinPool parallelism level is less than 2, then new thread is created for every task here

All async methods without an explicit Executor argument are performed using the ForkJoinPool.commonPool() (unless it does not support a parallelism level of at least two, in which case, a new Thread is created to run each task).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM