Files
javademos/docs/output/99-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

16 lines
1.0 KiB
Plaintext

$ java ScopedValuesBasics (JDK 25, no preview flag -- JEP 506 is final)
CHECK ok : isBound() is true inside where().run()
CHECK ok : get() returns "ankur" inside the binding
CHECK ok : a method several frames deep, given no parameter, still sees the binding
CHECK ok : isBound() is false again once run() has returned
CHECK ok : get() outside a binding throws NoSuchElementException, not null or a default value
CHECK ok : orElse(fallback) returns the fallback when unbound, no exception
CHECK ok : orElse(fallback) returns the real value when bound
CHECK ok : orElseThrow(supplier) throws exactly the supplied exception when unbound
CHECK ok : outer binding: ankur
CHECK ok : inner binding shadows the outer one: support-bot
CHECK ok : a method called from inside the inner scope sees the REBOUND value, not the original
CHECK ok : outer binding is restored, unchanged, once the inner where() block exits: ankur
CHECK ok : call(...) returns whatever the lambda returns -- USER.get().length() == 5
exit=0