Files
javademos/docs/output/98-basics.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.1 KiB
Plaintext

$ java GathererBasics (JDK 25)
windowFixed(3) of 1..7 = [[1, 2, 3], [4, 5, 6], [7]]
CHECK ok : windowFixed(3) groups into [1,2,3][4,5,6][7], last window is the short remainder
CHECK ok : windowFixed(0) throws IllegalArgumentException: 'windowSize' must be greater than zero
windowSliding(3) of 1..5 = [[1, 2, 3], [2, 3, 4], [3, 4, 5]]
CHECK ok : windowSliding(3) of 5 elements produces exactly 3 overlapping windows, each length 3
CHECK ok : windowSliding(3) on a 2-element stream still emits one short window: [[1, 2]]
CHECK ok : windowSliding(3) on an empty stream emits nothing
fold building a String: [1][2][3][4]
CHECK ok : fold("", acc+"[n]") over 1..4 builds "[1][2][3][4]" left to right
CHECK ok : fold's output stream has exactly one element, the final accumulation
scan running total of 1..5 = [1, 3, 6, 10, 15]
CHECK ok : scan(0, +) over 1..5 emits every prefix sum: [1,3,6,10,15]
fold(0,+) over 1..3 = [6]
scan(0,+) over 1..3 = [1, 3, 6]
CHECK ok : fold(0,+) over 1..3 emits just the final sum [6]
CHECK ok : scan(0,+) over 1..3 emits every partial sum [1,3,6]
exit=0