Summary
Small updates to java.util.concurrent.StructuredTaskScope accumulated since JEP 505 / JDK 25.
Problem
There are use-cases where it can be useful to get a result when a timeout occurs. The existing API always throws a TimeoutException if the timeout expires while (or before) waiting in join.
The join method is currently hostile to cases where code wants to catch InterruptedException and invoke join again.
Solution
The API changes in this update are:
Joiner:onTimeoutis added withjoinmethod changed to invoke this joiner method if a timeout is configured and the timeout expires before or while waiting. TheonTimeoutthrowsTimeoutExceptionor may do nothing. This allows forJoinerimplementation that are capable of returning a result from the subtasks that complete before the timeout expires.- The
configFunctionparameter to the 3-argopenis changed fromFunction<Configuration, Configuration>toUnaryOperator<Configuration>. Subtask::getandSubtask::exceptionchanged to consistently throw if called from any thread before the scope owner has joined.StructuredTaskScope::joinis now specified so that it may be called again if interrupted.- The parameter on
Joiner::onForkandJoiner::onCompleteis changed fromSubtask<? extends T>toSubtask<T>. Joiner.allSuccessOrThrowis changed to return a list of results instead of a stream of subtasks.Joiner.allUntilis changed to return a list of subtasks.Joiner.anySuccessfulResultOrThrowis renamed toanySuccessfulOrThrow.Joiner.allUntil(Predicate)is changed to allowjoinreturn the stream of all forked subtasks when the timeout expires.Joineris no longer a@FunctionalInterface.
Specification
API diffs (generated by apidiff tool) are attached
- csr of
-
JDK-8367857 Implement JEP 525: Structured Concurrency (Sixth Preview)
-
- Open
-
- relates to
-
JDK-8369479 Structured Concurrency: IllegalStateException on Subtask.get() after timeout
-
- Closed
-
- links to