Summary
Update java.util.concurrent.StructuredTaskScope for JEP 505: Structured Concurrency (Fifth Preview).
Problem
StructuredTaskScope has a public constructor and requires subclassing to implement different policies/outcome. The API includes ShutdownOnFailure and ShutdownOnSuccess for common cases; developers can extend StructuredTaskScope to implement other policies and APIs that make available the outcome. This design put constraints on future evolution of the base class.
StructuredTaskScope::join does not propagate exceptions. When using ShutdownOnFailure you need to call throwIfFailed after joining, otherwise the exceptions are lost. This is a hazard.
Solution
The main changes to the API are:
Change the API from using constructors to using static factory methods.
Introduce a new interface named
Joinerto handle subtask completion and produce the result for a main task waiting in thejoinmethod. Specifying aJoinerto the staticopenmethod in the updated API is equivalent to using a subclass in the existing API. TheJoinerinterface defines methods to obtain aJoinerfor common cases.Remove
ShutdownOnFailureandShutdownOnSuccess.Change the
joinmethod so that it returns the outcome or throws.
In addition, there are a number of other small updates:
- The
forkmethod is changed so that it cannot be called after joining. - The
joinmethod is changed so that it can only be called once. - Configuration that was provided with parameters for the constructor is changed so that it can be provided by a configuration function.
joinUntil(Instant)is removed and replaced by allowing a timeout be configured by the configuration function. The scope is cancelled if the timeout expires before the scope is closed.joinnow throwsStructuredTaskScope.FailedExceptionorStructuredTaskScope.TimeoutExceptionwhen the scope fails or the timeout elapses
Specification
A zip file of the API diffs is attached.
The API docs in the EA builds can also be browsed here: https://download.java.net/java/early_access/loom/docs/api/java.base/java/util/concurrent/StructuredTaskScope.html
- csr of
-
JDK-8342486 Implement JEP 505: Structured Concurrency (Fifth Preview)
-
- Resolved
-
- relates to
-
JDK-8306916 Implementation of Structured Concurrency (Preview)
-
- Closed
-