Runnable demos for the ankurm.com structured-concurrency-java article: the ExecutorService thread leak and its fix, every built-in Joiner, structure violations, timeouts, a custom Joiner, JSON thread dumps (in-process and jcmd), scoped values, javap diffs of the API on 25, 26, 27 and 28-ea, compiler output for six pieces of 25/26-era code, and the preview class-file trap between 27 and 28. Transcripts in output/. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01CifR2BE7PBvRy5hT8TS9oz
13 lines
455 B
Java
13 lines
455 B
Java
import java.util.concurrent.StructuredTaskScope;
|
|
|
|
/** The JDK 21-24 API that older tutorials still show. It is not in 25 or later. */
|
|
public class ShutdownOnFailure {
|
|
public static void main(String[] args) throws Exception {
|
|
try (var scope = new StructuredTaskScope.ShutdownOnFailure()) {
|
|
var user = scope.fork(() -> "Alice");
|
|
scope.join().throwIfFailed();
|
|
System.out.println(user.get());
|
|
}
|
|
}
|
|
}
|