CompletableFuture.runAsync
文档说明:
返回一个新的CompletableFuture,它由运行在给定操作后在
CompletableFuture.runAsync
中运行的任务异步完成。
但是据我所知,ForkJoinPool.commonPool()
仅在ForkJoinPool.commonPool()
时才向runAsync
提交任务。如果没有,它将为每个提交的任务手动创建一个新的ForkJoinPool.commonPool()
。
为什么会这样?
是,如果ForkJoinPool并行度级别小于2,则为每个任务ForkJoinPool.getCommonPoolParallelism() > 1
创建新线程
所有没有显式Executor参数的异步方法都是使用ForkJoinPool.commonPool()(除非它不支持并行度至少为2,在这种情况下,将创建一个新的线程来运行每个任务)。