Files
javademos/docs/output/98-collector-vs-gatherer.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

10 lines
591 B
Plaintext

$ java CollectorVsGatherer (JDK 25)
Collectors.groupingBy totals = {amy=19.75, bo=23.99}
CHECK ok : amy's total via groupingBy/summingDouble is 19.75
CHECK ok : bo's total via groupingBy/summingDouble is 23.99
scan -> filter -> map, one pipeline = [total=30, total=50, total=75]
CHECK ok : scan feeding straight into filter/map in the same pipeline gives [total=30, total=50, total=75]
windowFixed(2) over 7 elements, then collect(counting()) = 4
CHECK ok : collect(counting()) after gather() proves the gather result is still a Stream you can collect further: 4 windows
exit=0