Implement JEP 525: Structured Concurrency (Sixth Preview)

XMLWordPrintable

    • Type: CSR
    • Resolution: Unresolved
    • Priority: P3
    • 26
    • Component/s: core-libs
    • None
    • source, behavioral
    • minimal
    • There are some API changes so some usages of the preview API in JDK 25 will need some minor adjustments.
    • Java API
    • SE

      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:onTimeout is added with join method changed to invoke this joiner method if a timeout is configured and the timeout expires before or while waiting. The onTimeout throws TimeoutException or may do nothing. This allows for Joiner implementation that are capable of returning a result from the subtasks that complete before the timeout expires.
      • The configFunction parameter to the 3-arg open is changed from Function<Configuration, Configuration> to UnaryOperator<Configuration>.
      • Subtask::get and Subtask::exception changed to consistently throw if called from any thread before the scope owner has joined.
      • StructuredTaskScope::join is now specified so that it may be called again if interrupted.
      • The parameter on Joiner::onFork and Joiner::onComplete is changed from Subtask<? extends T> to Subtask<T>.
      • Joiner.allSuccessOrThrow is changed to return a list of results instead of a stream of subtasks. Joiner.allUntil is changed to return a list of subtasks.
      • Joiner.anySuccessfulResultOrThrow is renamed to anySuccessfulOrThrow.
      • Joiner.allUntil(Predicate) is changed to allow join return the stream of all forked subtasks when the timeout expires.
      • Joiner is no longer a @FunctionalInterface.

      Specification

      API diffs (generated by apidiff tool) are attached

            Assignee:
            Alan Bateman
            Reporter:
            Alan Bateman
            Viktor Klang
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: