Java SE API

StructuredTaskScope.open(Joiner, Function)

Java 25 fifth preview; create an owner-confined scope with a policy and configuration. Example not executed; use preview flags.

Formal Syntax & Structure

java syntaxjava
static <T,R> StructuredTaskScope<T,R> open(Joiner<? super T,? extends R> joiner, Function<Configuration,Configuration> configFunction)

Working Example

Example Snippetjava
import java.util.concurrent.StructuredTaskScope;import java.time.Duration;public class Main {    public static void main(String[] args) throws InterruptedException {        try (var scope = StructuredTaskScope.open(                StructuredTaskScope.Joiner.<Integer>awaitAllSuccessfulOrThrow(),                config -> config.withTimeout(Duration.ofSeconds(3)))) {            var subtotal = scope.fork(() -> 90);            var shipping = scope.fork(() -> 10);            scope.join();            System.out.println(subtotal.get() + shipping.get());        }    }}
Java Reference