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
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
$ jcmd <pid> GC.class_histogram (100000 subtasks parked, mode=sv, JDK 25)
|
||||
1: 100000 115102880 jdk.internal.vm.StackChunk ([email protected])
|
||||
2: 100000 16800000 java.lang.VirtualThread ([email protected])
|
||||
9: 100000 2400000 java.util.concurrent.StructuredTaskScopeImpl$SubtaskImpl ([email protected])
|
||||
128: 5 160 java.lang.ScopedValue$Carrier ([email protected])
|
||||
175: 5 80 java.lang.InheritableThreadLocal ([email protected])
|
||||
177: 5 80 java.lang.ScopedValue ([email protected])
|
||||
203: 2 48 java.lang.ScopedValue$Snapshot ([email protected])
|
||||
257: 1 32 java.util.concurrent.ThreadLocalRandom ([email protected])
|
||||
281: 1 24 java.util.concurrent.StructuredTaskScopeImpl$SubtaskImpl$AltResult ([email protected])
|
||||
292: 1 24 jdk.internal.vm.ScopedValueContainer$BindingsSnapshot ([email protected])
|
||||
324: 1 16 java.lang.ThreadLocal ([email protected])
|
||||
353: 1 16 java.util.concurrent.ThreadLocalRandom$Access$1 ([email protected])
|
||||
Total 1133788 172079104
|
||||
Reference in New Issue
Block a user