CompletableFuture.defaultExecutor()

Ben Manes ben.manes at gmail.com
Fri May 20 00:58:26 UTC 2022


Hi August,

I am asking in the context of CompletableFuture.runAsync(r) and friends. As
this defaults to using platform threads it can quickly exhaust the FJP
(e.g. futures blocking on other futures). A common footgun would be removed
if the default was changed to use virtual threads instead. I have seen this
surprise developers both in the context of Caffeine (AsyncCache) and
work-related projects. I suspect this change is the team's plan, but I have
not seen it discussed explicitly before. I do hope to switch Caffeine's
default executor setting when appropriate, since cache loads are
commonly I/O operations.

On Thu, May 19, 2022 at 3:08 PM August Nagro <augustnagro at gmail.com> wrote:

> Hi Ben, virtual threads by default use their own FJP, which uses a
> different execution mode then the common pool.
>
> Is Caffeine Cache the use case in mind here?
>
> On Wed, May 18, 2022, 4:48 AM Ben Manes <ben.manes at gmail.com> wrote:
>
>> The default executor for asynchronous tasks is either
>> ForkJoinPool.commonPool() or one that creates a new platform thread per
>> task if the JVM is restricted to a single logical cpu. Since
>> CompletableFuture is commonly used with I/O, it is easy to accidentally
>> block all of the common pool's threads. In the future, is this default
>> likely to change to use virtual threads?
>>
>> Cheers.
>>
>


More information about the loom-dev mailing list