Summary
-------
ForkJoinPool.invokeAll had incompatible Interruptiblity signature and behavior with its ExecutorService specs. This fixes the problem, while also adding an Uninterruptible version of the method for those who still need it.
Problem
-------
Usages of ForkJoinPool.invokeAll, when accessed as an ExecutorService (e.g., via Executors.newWorkStealingPool) had behavior incompatible with specs, causing Interrupts to unexpectedly be ignored in nearly all usages.
Solution
--------
Correct the signature and behavior of invokeAll, but also introduce method invokeAllUninterruptibly for use by any users who specifically want or need the prior version. Also add two overloads of ForkJoinTask.adaptInterruptible for uniformity.
Specification
-------------
The update invokeAll specs just inherit those of ExecutorService, so are left implicit.
ForkJoinPool.invokeAllUninterruptibly:
}
/**
* Uninterrupible version of {@code InvokeAll}. Executes the given
* tasks, returning a list of Futures holding their status and
* results when all complete, ignoring interrupts. {@link
* Future#isDone} is {@code true} for each element of the returned
* list. Note that a <em>completed</em> task could have
* terminated either normally or by throwing an exception. The
* results of this method are undefined if the given collection is
* modified while this operation is in progress.
*
* @apiNote This method supports usages that previously relied on an
* incompatible override of
* {@link ExecutorService#invokeAll(java.util.Collection)}.
*
* @param tasks the collection of tasks
* @param <T> the type of the values returned from the tasks
* @return a list of Futures representing the tasks, in the same
* sequential order as produced by the iterator for the
* given task list, each of which has completed
* @throws NullPointerException if tasks or any of its elements are {@code null}
* @throws RejectedExecutionException if any task cannot be
* scheduled for execution
* @since 22
*/
public <T> List<Future<T>> invokeAllUninterruptibly(Collection<? extends Callable<T>> tasks)
The two overloads for ForkJoinTask.adaptInterruptible include the same wording as the existing Callable version:
/**
* Returns a new {@code ForkJoinTask} that performs the {@code run}
* method of the given {@code Runnable} as its action, and returns
* the given result upon {@link #join}, translating any checked exceptions
* encountered into {@code RuntimeException}. Additionally,
* invocations of {@code cancel} with {@code mayInterruptIfRunning
* true} will attempt to interrupt the thread performing the task.
*
* @param runnable the runnable action
* @param result the result upon completion
* @param <T> the type of the result
* @return the task
*
* @since 22
*/
public static <T> ForkJoinTask<T> adaptInterruptible(Runnable runnable, T result)
/**
* Returns a new {@code ForkJoinTask} that performs the {@code
* run} method of the given {@code Runnable} as its action, and
* returns null upon {@link #join}, translating any checked
* exceptions encountered into {@code RuntimeException}.
* Additionally, invocations of {@code cancel} with {@code
* mayInterruptIfRunning true} will attempt to interrupt the
* thread performing the task.
*
* @param runnable the runnable action
* @return the task
*
* @since 22
*/
public static ForkJoinTask<?> adaptInterruptible(Runnable runnable)