On Wed, 6 Nov 2024 15:47:55 GMT, Alan Bateman <al...@openjdk.org> wrote:
> Changes for [JEP draft: Structured Concurrency (Fourth > Preview)](https://openjdk.org/jeps/8340343). The JEP isn't on the technical > roadmap yet. The proposal is to re-preview the API with some changes, > specifically: > > - A > [StructuredTaskScope](https://download.java.net/java/early_access/loom/docs/api/java.base/java/util/concurrent/StructuredTaskScope.html) > is now opened with a static factory method instead of a constructor. Once > opened, the API usage is unchanged: fork subtasks individually, join them as > a unit, process outcome, and close. > - In conjunction with moving to using a static open method, policy and > desired outcome is now selected by specifying a Joiner to the open method > rather than extending STS. A Joiner handles subtask completion and produces > the result for join to return. Joiner.onComplete is the equivalent of > overriding handleComplete previously. This change means that the subclasses > ShutdownOnFailure and ShutdownOnSuccess are removed, replaced by factory > methods on Joiner to get an equivalent Joiner. > - The join method is changed to return the result or throw > STS.FailedException, replacing the need for an API in subclasses to obtain > the outcome. This removes the hazard that was forgetting to call > throwIfFailed to propagate exceptions. > - Configuration that was provided with parameters for the constructor is > changed so that can be provided by a configuration function. > - joinUntil is replaced by allowing a timeout be configured by the > configuration function. This allows the timeout to apply the scope rather > than the join method. > > The underlying implementation is unchanged except that ThreadFlock.shutdown > and wakeup methods are no longer confined. The STS API implementation moves > to non-public StructuedTaskScopeImpl because STS is now an interface. A > non-public Joiners class is added with the built-in Joiner implementations. src/java.base/share/classes/java/util/concurrent/StructuredTaskScope.java line 122: > 120: * {@link #close() close} method always waits for threads executing > subtasks to finish, > 121: * even if the scope is cancelled, so execution cannot continue beyond > the {@code close} > 122: * method until the interrupted threads finish. Viktor has suggested that we move this paragraph up or at least make it more prominent. src/java.base/share/classes/java/util/concurrent/StructuredTaskScope.java line 337: > 335: * <a > href="{@docRoot}/java.base/java/util/concurrent/package-summary.html#MemoryVisibility"> > 336: * <i>happen-before</i></a> any actions taken by that subtask, which in > turn > 337: * <i>happen-before</i> the subtask result is {@linkplain Subtask#get() > retrieved}. Chen has suggested that this be expanded to specify a HB between onComplete and join. Viktor and I have discussed extending the existing text to deal with subtask outcome that "contributes" to the scope result but did not agree wording (note that this is a pre-existing short-coming in the spec, not a new issue). ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/21934#discussion_r1832464575 PR Review Comment: https://git.openjdk.org/jdk/pull/21934#discussion_r1832468226