Add structured-concurrency-final module: StructuredTaskScope final in JDK 28 (JEP 543), run on 28-ea, 27, 26 and 25
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
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
import java.time.Duration;
|
||||
import java.util.concurrent.StructuredTaskScope;
|
||||
|
||||
/** The JDK 25/26 timeout exception. In 27 the scope throws ExecutionException with a CancelledByTimeoutException cause. */
|
||||
public class OldTimeoutException {
|
||||
public static void main(String[] args) throws Exception {
|
||||
try (var scope = StructuredTaskScope.open(StructuredTaskScope.Joiner.<String>awaitAllSuccessfulOrThrow(),
|
||||
cf -> cf.withTimeout(Duration.ofMillis(50)))) {
|
||||
scope.fork(() -> { Thread.sleep(1000); return "late"; });
|
||||
scope.join();
|
||||
} catch (StructuredTaskScope.TimeoutException e) {
|
||||
System.out.println("timed out");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user