-
CSR
-
Resolution: Unresolved
-
P4
-
None
-
source
-
minimal
-
Summary
Improve the performance of delayed task handling with an update to java.util.concurrent.ForkJoinPool
to implement ScheduledExecutorService
.
Problem
In common network-related applications, delayed tasks to handle timeouts are scheduled but are usually cancelled. This may lead to excessive contention and avoidable locking, especially with virtual threads, in turn using ForkJoinPool
. ScheduledThreadPoolExecutor
is ill-suited for many (if not most) of its applications, and is a performance bottleneck with virtual threads and CompletableFuture
.
Solution
Lazily connect support for ScheduledExecutorService
to any ForkJoinPool
instance, this includes the common pool.
In API terms java.util.concurrent.ForkJoinPool
is updated to implement ScheduledExecutorService
, thus adding 3 methods to its API:
public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit)
public <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit)
public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit)
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit)
Three other methods added: to submit a task with a timeout, a method to disable delayed tasks on shutdown, and a method to get an estimate of the number of delayed tasks that are schedueld.
public <V> ForkJoinTask<V> submitWithTimeout(Callable<V> callable,
long timeout, TimeUnit unit,
Consumer<? super ForkJoinTask<V>> timeoutAction)
public void cancelDelayedTasksOnShutdown()
public int getDelayedTaskCount()
CompletableFuture
is updated for the corner case that the ForkJoinPool common pool is configured with zero parallelism. The async methods were to create a new Thread
for each async task. This is changed, in a backward compatible way, to consistently use the common pool.
Finally, while in the area, the description of the corePoolSize
parameter in the 10-arg ForkJoinPool
constructor is changed to specify that the parameter is ignored. The parameter is already ignored, this change just aligns the spec with the long standing implementation.
Specification
A zip file is attached with the API diffs.
- csr of
-
JDK-8319447 Improve performance of delayed task handling
-
- New
-