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,10 @@
|
||||
$ java --enable-preview -Xmx6g ScopedValueVsThreadLocalMemory 500000 (JDK 25)
|
||||
threads per scenario: 500000, 5 bound values each, forked via StructuredTaskScope
|
||||
CHECK ok : every one of 1000 subtasks read all 5 scoped values correctly
|
||||
CHECK ok : every one of 1000 subtasks read all 5 inherited ThreadLocal values correctly
|
||||
CHECK ok : every one of 500000 subtasks read all 5 scoped values correctly
|
||||
ScopedValue: 500000 live subtasks, 5 bound values each, heap delta = 531.8 MB (1115 bytes/thread)
|
||||
CHECK ok : every one of 500000 subtasks read all 5 inherited ThreadLocal values correctly
|
||||
ThreadLocal: 500000 live subtasks, 5 inherited values each, heap delta = 546.1 MB (1145 bytes/thread)
|
||||
ThreadLocal used 1.0x the heap ScopedValue used, for holding the identical 5 values live on 500000 threads
|
||||
exit=0
|
||||
Reference in New Issue
Block a user