Java Concurrency Interview

Virtual threads and structured concurrency question 118 of 180 senior

What are ShutdownOnFailure and ShutdownOnSuccess for?

ShutdownOnFailure is the "all must succeed" case, which is most fan-out: three service calls to assemble one page, where any failure makes the whole page impossible. The first exception cancels the other forks immediately rather than leaving them running for results nobody will use.

ShutdownOnSuccess is the racing case: query three replicas, or a cache and an origin, and take whichever answers first, cancelling the losers.

In JDK 25 these became joiners passed to StructuredTaskScope.open(...) (Joiner.allSuccessfulOrThrow(), Joiner.anySuccessfulResultOrThrow()), with custom joiners for policies such as "wait for a quorum". The concepts are the same; only the spelling changed.

structured-concurrency

Quiz yourself on Virtual threads and structured concurrency Suggest a correction