executors: ExecutorService lifecycle companion code
Adds the executors module: shutdown() vs shutdownNow(), the graceful two-phase shutdown pattern, AutoCloseable/try-with-resources (JDK 19+), newVirtualThreadPerTaskExecutor() timing vs a bounded pool, and the submit()-without-get() lost-exception trap. 5 runnable demos, 1 JUnit correctness test class (23 tests), 6 captured output transcripts. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01FhzLY5p6okFva3qsnsRyvM
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
=== execute(): uncaught exception reaches the default handler, gets printed ===
|
||||
Exception in thread "pool-1-thread-1" java.lang.RuntimeException: boom from execute()
|
||||
at com.ankurm.executors.LostExceptionTrapDemo.lambda$main$0(LostExceptionTrapDemo.java:22)
|
||||
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1090)
|
||||
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:614)
|
||||
at java.base/java.lang.Thread.run(Thread.java:1474)
|
||||
|
||||
=== submit(): same exception, but nobody calls get() - dead silence ===
|
||||
main: task's Future exists (isDone=true), but its exception was never printed anywhere - it's just sitting inside the Future
|
||||
|
||||
=== submit() + get(): the SAME exception, now surfaced by calling get() ===
|
||||
main: caught ExecutionException, cause = java.lang.RuntimeException: boom from submit(), retrieved via get()
|
||||
done
|
||||
Reference in New Issue
Block a user