Files
javademos/docs/output/98-mapconcurrent.txt
T
Claude 6b5a918278 Add two standalone modules: Stream Gatherers (JEP 485) and Scoped Values vs ThreadLocal (JEP 506)
gatherers/: windowFixed, windowSliding, fold, scan, mapConcurrent, a custom
Gatherer (dedupeConsecutive, takeUntil), and a Collector-vs-Gatherer comparison.
Verified: windowSliding emits one short window on a too-short stream rather than
shrinking to empty like windowFixed; mapConcurrent waits for in-flight siblings
to finish (~901ms) rather than cancelling them when one mapper throws.

scoped-values/: ScopedValue API and rebinding, why plain threads (virtual or
platform) do not inherit a binding while a StructuredTaskScope subtask does,
and the memory cost vs InheritableThreadLocal measured two ways -- a noisy
heap-delta first pass, then a precise jcmd GC.class_histogram object census
(5 shared Carrier objects vs ~700,000 copied ThreadLocalMap/Entry objects for
100,000 threads).

Companion code for the ankurm.com posts "Java Stream Gatherers (JEP 485)" and
"Scoped Values vs ThreadLocal in Java 25: Migration Guide with Virtual Threads".

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FtpJvZfg4nvLvtzgJTDWpB
2026-09-24 04:27:12 +00:00

19 lines
1.2 KiB
Plaintext

$ java MapConcurrentDemo (JDK 25)
mapConcurrent(4, ...) results, completion order reversed: [10, 20, 30, 40]
CHECK ok : mapConcurrent output preserves encounter order [10,20,30,40] even though task 1 finishes last
mapConcurrent(2, ...) over 8 tasks, peak concurrent in-flight = 2
CHECK ok : all 8 tasks completed
CHECK ok : peak in-flight never exceeded maxConcurrency=2, measured peak=2
CHECK ok : the cap is actually reached, not just respected -- measured peak=2
VirtualThread[#38]/runnable@ForkJoinPool-1-worker-2 virtual=true
VirtualThread[#39]/runnable@ForkJoinPool-1-worker-2 virtual=true
VirtualThread[#40]/runnable@ForkJoinPool-1-worker-2 virtual=true
VirtualThread[#41]/runnable@ForkJoinPool-1-worker-2 virtual=true
VirtualThread[#42]/runnable@ForkJoinPool-1-worker-2 virtual=true
VirtualThread[#37]/runnable@ForkJoinPool-1-worker-1 virtual=true
CHECK ok : every mapConcurrent worker thread reports isVirtual() == true
CHECK ok : 6 elements produced 6 distinct virtual threads -- one per element, not a shared pool
mapConcurrent propagated: boom at element 3 after 901ms
CHECK ok : the failure only surfaced after 901ms -- mapConcurrent waited for the other 4 in-flight tasks, it did not cancel them
exit=0