Scrivio Interview library
LeadershipAdvanced6 min read · updated 12 November 2026

A team wants to use StructuredTaskScope in production services on Java 25 with --enable-preview because it simplifies fan-out code. What is your decision and what conditions would you set?

I would not let preview APIs spread freely through production services, because a preview API can change or disappear in the next release, and classes compiled with preview features only run on the exact same JDK feature release with --enable-preview. If the team's benefit is real, I would allow it under conditions: StructuredTaskScope only behind one small internal abstraction, an explicit and time-boxed decision with an owner tracking the JEP, and executors with explicit cancellation as the fallback until the API is final.

Why this question is asked

Leadership questions about preview features are really questions about risk and reversibility. The team is right that StructuredTaskScope makes fan-out code shorter and safer. The question is what happens to dozens of services when the API changes, and who pays for it. Interviewers want to hear that we understand the technical constraints of preview features and that we can turn a yes-or-no argument into a decision with conditions. In this answer, we will recap what preview means in the JDK, look at the concrete costs it creates for upgrades, design the abstraction that contains the risk, compare it with the executor alternative, and set the conditions for the decision.

1What Preview Means in the JDK

A preview feature is a fully specified and implemented part of the platform that is not yet permanent. The JDK ships it so that developers can try it and give feedback, and the JEP process explicitly allows it to change or be removed in the next release. StructuredTaskScope shows that this is not theoretical: it went from an incubator module in Java 19 to its fifth preview in Java 25, and on the way the main entry point changed from constructors such as new StructuredTaskScope.ShutdownOnFailure() to a static open() method with Joiner policies. Code written for Java 21 does not compile unchanged on Java 25.

So the team's code is not wrong; it is code that we know we will have to edit, on a schedule set by the JDK rather than by us.

2The Upgrade Cost Nobody Mentions

The bigger cost is operational. When javac compiles a class that uses a preview feature, it marks the class file as depending on preview features of exactly that release. The JVM refuses to load such a class unless it runs the same feature release with --enable-preview.

Shell
javac --release 25 --enable-preview FanOut.java // class file version 69.65535
java FanOut // fails: preview features are not enabled
java --enable-preview FanOut // runs on JDK 25
// on JDK 26: the class file must be recompiled, even with --enable-preview

Notice what this means for a fleet. Every service using the API must be rebuilt for each new JDK, and any shared library that uses it pins every consumer to the same JDK release. We can no longer move one service to a new JDK while the library stays on the old one, and the flag has to be added to every launch script, container image and test run. This is the risk I would explain to the team, because it affects platform upgrades for everyone, not only the people who wrote the fan-out code.

3Containing the Risk Behind One Abstraction

If we allow it, the rule is that application code never touches StructuredTaskScope directly. Instead, a small internal module offers the two or three fan-out shapes we actually use, and only that module imports the preview API.

Java
public final class FanOut {
// the only class in the company that imports the preview API
public static <A, B, R> R both(Callable<A> a, Callable<B> b, BiFunction<A, B, R> combine)
throws InterruptedException {
try (var scope = StructuredTaskScope.open()) {
var ra = scope.fork(a);
var rb = scope.fork(b);
scope.join(); // a failure cancels the other call
return combine.apply(ra.get(), rb.get());
}
}
}
// application code: FanOut.both(() -> users.find(id), () -> orders.find(id), Response::new)

When the API changes in the next JDK, one class changes, and its tests tell us whether the behaviour stayed the same. The abstraction also gives us a place to add timeouts, metrics and logging consistently. A good sign the abstraction is right is that we could implement it on executors too, which leads to the alternative.

4The Alternative: Executors With Explicit Cancellation

Until the API is final, we can get most of the safety with stable APIs: submit to an executor that creates one virtual thread per task, and cancel the remaining futures when one fails or when the caller gives up.

Java
try (var exec = Executors.newVirtualThreadPerTaskExecutor()) {
Future<User> u = exec.submit(() -> users.find(id));
Future<List<Order>> o = exec.submit(() -> orders.find(id));
try {
return new Response(u.get(), o.get());
} catch (ExecutionException e) {
u.cancel(true); o.cancel(true); // interrupt whatever is still running
throw e;
}
} // close() waits for all tasks to finish
Options for fan-out on Java 25
OptionBenefitCost
Preview API everywhereShortest, safest code todayEvery service edits and recompiles per JDK
Preview API behind FanOutSame safety, one place to changeStill needs --enable-preview in every service
Executors behind FanOutStable API, no flagsManual cancellation, no task tree in dumps
The abstraction is what makes the first-row risk manageable.

It is more code and easier to get wrong, which is exactly what the team is trying to avoid, and the thread dump will not show the parent-child tree. But it runs on any JDK from 21 on without flags. Putting either version behind the same FanOut class means we can switch between them without touching callers.

5Making the Decision Explicit and Time-Boxed

Whichever way we go, I would write the decision down as a short record: what we allowed, in which services, why, and when we review it. An owner tracks the JEP, reads each JDK release's notes for changes to the API, and opens the migration ticket when it changes. A sensible time box is one JDK release cycle, six months, with a review at each new feature release. If the API becomes final, we remove --enable-preview and the abstraction can stay as a thin helper. If it changes, we update one class. If it is withdrawn, we switch the abstraction to the executor version.

My own decision would be this: allow it for services that do heavy fan-out and are owned by teams willing to follow the JDK cadence, only through the shared abstraction, and never in shared libraries that other teams depend on. Everyone else uses the executor version of the same abstraction. That gives the team the benefit they want while keeping the rest of the organisation free to upgrade on its own schedule.

6Follow-up questions

Why not wait until the API is final?

That is the safest choice, and for most teams I would recommend it. But fan-out bugs such as leaked tasks are real today, and a team that understands the costs can get value now. The abstraction makes the difference between those two positions small, because switching later is one class either way.

Does --enable-preview affect anything else in the JVM?

It enables every preview language feature and API of that release for the classes compiled with it, not just StructuredTaskScope. That is another reason to keep its use small and visible: a developer could start using another preview feature without anyone noticing, and the build should fail if preview APIs appear outside the allowed module.

How would you enforce that only one module uses the preview API?

With an architecture test, for example an ArchUnit rule that no class outside the fan-out package depends on java.util.concurrent.StructuredTaskScope, and by enabling the preview flag only in that module's compiler settings. If another module tries to use it, the build fails, which is cheaper than finding it in code review.

7Conclusion

In this answer, we saw that preview APIs can change or be removed, that StructuredTaskScope already changed between previews, and that classes compiled with preview features run only on the same JDK feature release with --enable-preview, which couples every user to the JDK version. The way to say yes safely is to hide the API behind a small internal abstraction, keep an executor-based implementation as the fallback, and make the decision explicit, time-boxed and owned by someone tracking the JEP.

What to say in the interviewAbout 80 seconds aloud

Open with

My answer would be a conditional yes. The team is right that StructuredTaskScope makes fan-out safer, because a failure cancels sibling tasks and nothing outlives the method. But it is a preview API in Java 25, and preview APIs can change or be removed; this one already changed from constructors like ShutdownOnFailure to the open method with joiners.

Then, if they want more

There is also an operational cost: classes compiled with preview features only load on the same JDK feature release with --enable-preview, so every service has to be recompiled for each new JDK and any library using it pins its consumers. So I would set conditions.

Application code never imports the preview API; it calls a small internal FanOut class, and only that class uses StructuredTaskScope, enforced with an architecture test. We keep an executor-based implementation of the same class, using a virtual-thread-per-task executor with explicit cancellation, so we can switch without touching callers. I would not allow it in shared libraries.

And I would record the decision with an owner who tracks the JEP and a review at each JDK release, about every six months. When the API goes final, we drop the flag; if it changes, we update one class.

About this answer

Last updated
12 November 2026
Versions it names
Java 25, Java 19, Java 21, Java 26
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
JEP 444, Virtual Threads
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "A team wants to use StructuredTaskScope in production services on Java 25 with...": https://scrivio-interview-library.netlify.app/java/virtual-threads/e13e33fde0/