StructuredTaskScope From Java 21 to Java 28: Every API Change and How to Migrate
Structured concurrency took seven previews to become final in Java 28. The class-based API of Java 21 to 24, the Joiner redesign of Java 25, the refinements in 26 and 27, and a migration checklist with the same trip quote written for Java 21, 25 and 27/28.
kvi5hnuCode Sprout team member8 min readOn this page
Structured concurrency is one of the longest-running previews in Java's history. It becomes final in Java 28 (JEP 543, due in March 2027), after two incubator releases and seven previews, and the API changed substantially along the way. Most tutorials and blog posts, including ones written for Java 25, show one of the earlier shapes. This article maps every version to the final one, so you can read old code and migrate it.

The versions
| Java | JEP | Stage | What changed |
|---|---|---|---|
| 19 | 428 | incubator | first version, in jdk.incubator.concurrent; fork returned a Future |
| 20 | 437 | incubator | subtasks inherit scoped values |
| 21 | 453 | preview 1 | moved to java.util.concurrent; fork returns Subtask |
| 22, 23, 24 | 462, 480, 499 | previews 2–4 | no API changes |
| 25 | 505 | preview 5 | redesign: open() factories, Joiner, Configuration; FailedException |
| 26 | 525 | preview 6 | allSuccessfulOrThrow returns List, anySuccessfulOrThrow rename, UnaryOperator configuration, onTimeout |
| 27 | 533 | preview 7 | ExecutionException, Joiner<T, R, R_X>, timeout(), CancelledByTimeoutException, awaitAll removed |
| 28 | 543 | final | same API as Java 27 |
Java 21 to 24: subclasses and shutdown
The first preview was a class. You created a scope with new, usually one of two built-in subclasses, and the policy was the subclass:
StructuredTaskScope.ShutdownOnFailure: like today's default. Afterjoin(), you calledthrowIfFailed(), which threwExecutionExceptionwith the failure as its cause.StructuredTaskScope.ShutdownOnSuccess<T>: like today'sanySuccessfulOrThrow. Afterjoin(),result()returned the first success.- Custom policies subclassed
StructuredTaskScopeand overrodehandleComplete(Subtask), callingshutdown()to cancel. - Deadlines were passed to the join:
joinUntil(Instant), which threwjava.util.concurrent.TimeoutException. - The scope's name and thread factory were constructor arguments.
Java 25: the Joiner redesign
JEP 505 replaced the class with a sealed interface and static open() factories. The policy moved into a separate Joiner object, configuration (name, thread factory, timeout) moved into Configuration, and join() itself produced the outcome. Failures were reported as the unchecked StructuredTaskScope.FailedException, and timeouts as the unchecked StructuredTaskScope.TimeoutException. Built-in joiners included awaitAllSuccessfulOrThrow(), allSuccessfulOrThrow() (returning a Stream<Subtask<T>>), anySuccessfulResultOrThrow(), awaitAll() and allUntil(predicate).
Java 26 and 27: refinements
Java 26 (JEP 525) made smaller changes: allSuccessfulOrThrow() returned a List<T> of results, anySuccessfulResultOrThrow() became anySuccessfulOrThrow(), the configuration function became a UnaryOperator<Configuration>, and joiners gained an onTimeout() hook.
Java 27 (JEP 533) changed how outcomes are typed:
- The built-in joiners throw the checked
ExecutionException, likeFuture.get(), instead ofFailedException. StructuredTaskScope<T, R, R_X>andJoiner<T, R, R_X>gained a third type parameter, the exception thatjoin()throws, and each throwing joiner got aFunction<Throwable, X>overload for choosing it.onTimeout()was replaced bytimeout(), which produces the outcome when the deadline expires. The built-in throwing joiners report a timeout asExecutionExceptionwith aCancelledByTimeoutExceptioncause.awaitAll()was removed.allUntil(s -> false)does the same job.open(UnaryOperator<Configuration>)configures a scope with the default joiner.
Java 28 (JEP 543) makes the Java 27 API final, with no changes.
One quote, three APIs
The same operation, a trip quote that needs a flight and a hotel within 2 seconds and a race between rate mirrors, in each API. All three were compiled and run: the Java 21 version on JDK 21 with --enable-preview, and the Java 25 version on JDK 25. Each printed LIS-OSL + Hotel Fjord and rates from ap-south.
import java.time.Instant;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.StructuredTaskScope;
import java.util.concurrent.StructuredTaskScope.Subtask;
import java.util.concurrent.TimeoutException;
// Java 21 to 24 preview API (JEP 453, 462, 480, 499)
public class QuoteJava21 {
static String findFlight() throws InterruptedException { Thread.sleep(100); return "LIS-OSL"; }
static String findHotel() throws InterruptedException { Thread.sleep(200); return "Hotel Fjord"; }
static String mirror(String name, int ms) throws InterruptedException { Thread.sleep(ms); return "rates from " + name; }
static String quote() throws InterruptedException, ExecutionException, TimeoutException {
try (var scope = new StructuredTaskScope.ShutdownOnFailure("trip", Thread.ofVirtual().factory())) {
Subtask<String> flight = scope.fork(QuoteJava21::findFlight);
Subtask<String> hotel = scope.fork(QuoteJava21::findHotel);
scope.joinUntil(Instant.now().plusSeconds(2)); // deadline passed to the join call
scope.throwIfFailed(); // throws ExecutionException on failure
return flight.get() + " + " + hotel.get();
}
}
static String rates() throws InterruptedException, ExecutionException {
try (var scope = new StructuredTaskScope.ShutdownOnSuccess<String>()) {
scope.fork(() -> mirror("eu-west", 300));
scope.fork(() -> mirror("ap-south", 100));
scope.join();
return scope.result(); // first success; ExecutionException if all failed
}
}
public static void main(String[] args) throws Exception {
System.out.println(quote());
System.out.println(rates());
}
}
import java.time.Duration;
import java.util.concurrent.StructuredTaskScope;
import java.util.concurrent.StructuredTaskScope.Joiner;
import java.util.concurrent.StructuredTaskScope.Subtask;
// Java 25 preview API (JEP 505)
public class QuoteJava25 {
static String findFlight() throws InterruptedException { Thread.sleep(100); return "LIS-OSL"; }
static String findHotel() throws InterruptedException { Thread.sleep(200); return "Hotel Fjord"; }
static String mirror(String name, int ms) throws InterruptedException { Thread.sleep(ms); return "rates from " + name; }
static String quote() throws InterruptedException {
try (var scope = StructuredTaskScope.open(Joiner.<String>awaitAllSuccessfulOrThrow(),
cf -> cf.withName("trip").withTimeout(Duration.ofSeconds(2)))) {
Subtask<String> flight = scope.fork(QuoteJava25::findFlight);
Subtask<String> hotel = scope.fork(QuoteJava25::findHotel);
scope.join(); // throws FailedException or TimeoutException (both unchecked)
return flight.get() + " + " + hotel.get();
}
}
static String rates() throws InterruptedException {
try (var scope = StructuredTaskScope.open(Joiner.<String>anySuccessfulResultOrThrow())) {
scope.fork(() -> mirror("eu-west", 300));
scope.fork(() -> mirror("ap-south", 100));
return scope.join();
}
}
public static void main(String[] args) throws Exception {
System.out.println(quote());
System.out.println(rates());
}
}
import java.time.Duration;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.StructuredTaskScope;
import java.util.concurrent.StructuredTaskScope.Joiner;
import java.util.concurrent.StructuredTaskScope.Subtask;
// Java 27 preview (JEP 533) = Java 28 final (JEP 543)
public class QuoteJava27 {
static String findFlight() throws InterruptedException { Thread.sleep(100); return "LIS-OSL"; }
static String findHotel() throws InterruptedException { Thread.sleep(200); return "Hotel Fjord"; }
static String mirror(String name, int ms) throws InterruptedException { Thread.sleep(ms); return "rates from " + name; }
static String quote() throws InterruptedException, ExecutionException {
try (var scope = StructuredTaskScope.open(
cf -> cf.withName("trip").withTimeout(Duration.ofSeconds(2)))) {
Subtask<String> flight = scope.fork(QuoteJava27::findFlight);
Subtask<String> hotel = scope.fork(QuoteJava27::findHotel);
scope.join(); // throws ExecutionException (cause: failure or CancelledByTimeoutException)
return flight.get() + " + " + hotel.get();
}
}
static String rates() throws InterruptedException, ExecutionException {
try (var scope = StructuredTaskScope.open(Joiner.<String>anySuccessfulOrThrow())) {
scope.fork(() -> mirror("eu-west", 300));
scope.fork(() -> mirror("ap-south", 100));
return scope.join();
}
}
public static void main(String[] args) throws Exception {
System.out.println(quote());
System.out.println(rates());
}
}
The Java 21 code doesn't compile on Java 25 (ShutdownOnFailure and ShutdownOnSuccess no longer exist), and the Java 25 code doesn't compile on Java 27 (anySuccessfulResultOrThrow is gone, and ExecutionException must be handled).
Migration checklist
From Java 21–24 to Java 27/28:
| Java 21–24 | Java 27/28 |
|---|---|
new StructuredTaskScope.ShutdownOnFailure() + join() + throwIfFailed() | StructuredTaskScope.open() + join() (throws ExecutionException) |
new StructuredTaskScope.ShutdownOnSuccess<T>() + join() + result() | open(Joiner.<T>anySuccessfulOrThrow()) + join() returns the result |
throwIfFailed(e -> new MyException(e)) | a joiner's Function overload, such as awaitAllSuccessfulOrThrow(MyException::new) |
joinUntil(deadline) | cf -> cf.withTimeout(duration), counted from open() |
new ShutdownOnFailure(name, factory) | cf -> cf.withName(name).withThreadFactory(factory) |
subclass overriding handleComplete, calling shutdown() | a Joiner whose onComplete returns true to cancel |
scope.shutdown() from the owner | no direct equivalent: cancel through the joiner |
From Java 25–26 to Java 27/28:
| Java 25–26 | Java 27/28 |
|---|---|
catch (StructuredTaskScope.FailedException e) | catch (ExecutionException e), or a custom type via a Function overload |
catch (StructuredTaskScope.TimeoutException e) | ExecutionException whose cause is CancelledByTimeoutException |
anySuccessfulResultOrThrow() (Java 25) | anySuccessfulOrThrow() |
allSuccessfulOrThrow() → Stream<Subtask<T>> (Java 25) | allSuccessfulOrThrow() → List<T> |
awaitAll() | allUntil(s -> false) |
custom Joiner<T, R> with result() throws Throwable | Joiner<T, R, R_X> with result() throws R_X, plus timeout() |
onTimeout() (Java 26) | timeout(), which returns the outcome or throws |
open(joiner, Function<Configuration, Configuration>) (Java 25) | open(joiner, UnaryOperator<Configuration>) |
Because ExecutionException is checked, the compiler finds every place that needs attention: methods that used to let the unchecked FailedException propagate now need a throws clause, a catch, or a joiner that throws an unchecked type.
Reading older material
When you read about structured concurrency, check which API it uses:
ShutdownOnFailure,ShutdownOnSuccess,throwIfFailed,joinUntil: Java 21 to 24.open()andJoinerwithFailedException: Java 25 or 26.ExecutionExceptionfromjoin(),CancelledByTimeoutException, three type parameters: Java 27 or later.
The ideas didn't change across versions: owner thread, fork and join, cancellation of siblings, close waiting for all subtasks, nesting, and visibility guarantees. Only the API shape around them did. The concepts in articles 26 to 36 apply to all versions. The API details, such as joiners, configuration and timeout outcomes, are those of Java 27 and 28.
What's current
- Java 28 (JEP 543, GA March 2027) makes
StructuredTaskScopea standard API. No--enable-previewflag is needed. - Java 27 is the current release and has the same API as a preview: compile with
--release 27 --enable-preview, run with--enable-preview. - Java 25 is the current long-term-support release, with the older Java 25 preview API. If you're on 25 and want to use structured concurrency, isolate it behind a small helper so that moving to the final API later is a local change.
Common questions
Is it safe to use a preview API in production? It works, but every Java upgrade can break your code, as this article shows. Each preview only runs on the exact release it was compiled for. Most teams wait for the final version or confine preview code to a small, well-tested module.
Why did the API change so much?
Previews exist to collect feedback. Users found the subclass-based policies awkward and the timeout handling inflexible, so Java 25 separated policy (Joiner) from structure. Later rounds aligned the exceptions with Future and made timeouts a joiner decision.
Will code written for Java 27 run on Java 28?
Yes. Java 28 makes the Java 27 API final without changes. You only stop passing --enable-preview.
Did the behaviour change, or just the API?
Mostly the API. Cancellation by interruption, close() waiting for all subtasks, owner confinement and nesting rules have been stable since Java 21. The main behaviour change is timeouts, which are now an outcome decided by the joiner instead of a fixed exception.
Summary
- Structured concurrency incubated in Java 19 and 20, previewed in Java 21 to 27, and is final in Java 28.
- Java 21 to 24 used subclasses (
ShutdownOnFailure,ShutdownOnSuccess),throwIfFailed()andjoinUntil(). - Java 25 introduced
open(),JoinerandConfiguration, with the uncheckedFailedException. Java 26 refined names and return types. - Java 27, final in Java 28, throws
ExecutionException, adds theR_Xtype parameter,timeout()andCancelledByTimeoutException, and removesawaitAll(). - The concepts are unchanged across versions, so migration is mostly mechanical, and the checked exception lets the compiler find the places to change.
Practice questions
You find this code in a project: try (var scope = new StructuredTaskScope.ShutdownOnFailure()) { ...; scope.join().throwIfFailed(); ... }. Which Java versions does it target, and what's the Java 28 equivalent?
Answer
Java 21 to 24, the class-based preview. In Java 28: try (var scope = StructuredTaskScope.open()) { ...; scope.join(); ... }, with join() throwing ExecutionException on the first failure, just as throwIfFailed() did.
A Java 25 service catches StructuredTaskScope.TimeoutException to return a "too slow" response. How must that code change for Java 27?
Answer
There's no TimeoutException from join() any more. With the built-in throwing joiners, a timeout makes join() throw ExecutionException whose cause is StructuredTaskScope.CancelledByTimeoutException. Catch ExecutionException and check e.getCause() instanceof CancelledByTimeoutException.
A Java 25 custom joiner implements Joiner<Offer, Optional<Offer>> with result() throws Throwable. List the changes needed for Java 27.
Answer
Add the exception type parameter, for example Joiner<Offer, Optional<Offer>, RuntimeException>. Narrow result() to throws R_X (or no throws clause for RuntimeException). Change the callbacks' parameter type to Subtask<Offer>. Implement timeout() if the joiner may be used with a timeout, returning a partial outcome or throwing an exception with a CancelledByTimeoutException cause.
Review quiz
Test yourself on Part 4 with the Part 4 review quiz: Structured Concurrency in Java. It covers the problems with unstructured concurrency, scope rules, subtasks, joiners, exceptions, timeouts, custom joiners, memory visibility, nesting, observability and the API's history.
Previous: Observing Structured Concurrency: Scope Names, Thread Dumps and Task Trees
Next: Passing Context in Java: Parameter Pollution and Why Thread-Locals Were Used

More in Modern Java Concurrency
Quiz: Java Concurrency Changes From Java 21 to Java 28
Sixteen questions on what changed release by release: virtual threads final in 21, synchronized without pinning in 24, scoped values final in 25, and the long road of structured concurrency from subclasses to open() and Joiner, the Java 26 and 27 refinements, and final in 28.
Quiz: Java Concurrency's Delicate Details
Twenty edge cases of modern Java concurrency that surprise experienced developers: virtual thread priorities and names, semaphores without owners, null scoped values, cancelling a CompletableFuture, pool sizing with unbounded queues, and StructuredTaskScope's strict rules.
Quiz: Java Concurrency Interview Questions (Virtual Threads, Structured Concurrency, Scoped Values)
Twenty questions of the kind interviewers ask about modern Java concurrency: platform vs virtual threads, pinning, pools and limits, CompletableFuture, structured concurrency, scoped values vs ThreadLocal, reactive programming, and production diagnostics.
Quiz: Modern Java Concurrency Final Exam (All 7 Parts)
The final exam for the modern Java concurrency course: thirty questions across all seven parts, from platform threads, pools and CompletableFuture through virtual threads, the scheduler, structured concurrency, scoped values, reactive streams and frameworks.
Discussion
Sign in to ask a question or share what you learned.