Reputation: 982
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?
Upvotes: 4
Views: 444
Reputation: 40068
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).
Upvotes: 0