Files
java-core-examples/executors/output/04-virtual-thread-per-task-executor.txt
T
asmhatreandClaude Sonnet 5 bc5153d2a5 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
2026-09-30 06:54:17 +00:00

11 lines
507 B
Plaintext

Running 5000 tasks that each sleep 50ms.
sample task thread: VirtualThread[#22]/runnable@ForkJoinPool-1-worker-1
newVirtualThreadPerTaskExecutor(): 5000/5000 tasks completed in 121ms
(121ms is close to the 50ms a single task takes - every task ran concurrently, nothing waited for a free worker)
sample task thread: Thread[#5027,pool-1-thread-1,5,main]
newFixedThreadPool(20): 5000/5000 tasks completed in 12556ms
(12556ms is roughly 250 rounds of 50ms each - only 20 tasks are ever running at once)
done