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
25 lines
823 B
Plaintext
25 lines
823 B
Plaintext
=== shutdown(): lets running AND already-queued tasks finish ===
|
|
task-0: started
|
|
task-1: started
|
|
main: called shutdown() - isShutdown=true, isTerminated=false
|
|
task-0: finished normally
|
|
task-2: started
|
|
task-1: finished normally
|
|
task-3: started
|
|
task-3: finished normally
|
|
task-4: started
|
|
task-2: finished normally
|
|
task-5: started
|
|
task-4: finished normally
|
|
task-5: finished normally
|
|
main: awaitTermination returned true - all 6 tasks ran to completion, none were skipped
|
|
|
|
=== shutdownNow(): interrupts running tasks, abandons queued ones ===
|
|
task-0: started
|
|
task-1: started
|
|
main: called shutdownNow() - 4 queued tasks abandoned, never started
|
|
task-1: interrupted, exiting early
|
|
task-0: interrupted, exiting early
|
|
main: awaitTermination returned true - the 2 running tasks were interrupted mid-sleep, not allowed to finish
|
|
done
|