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
24 lines
984 B
Bash
Executable File
24 lines
984 B
Bash
Executable File
#!/usr/bin/env bash
|
|
# Stream Gatherers (JEP 485, final since JDK 24, no preview flag needed on 25+). Every demo
|
|
# asserts its own claims (see Check.java), so a green transcript means the post's claims still
|
|
# hold on whatever JDK25 points at.
|
|
# ./scripts/gatherers.sh -> docs/output/98-basics.txt 98-mapconcurrent.txt
|
|
# 98-custom-gatherer.txt 98-collector-vs-gatherer.txt
|
|
set -uo pipefail
|
|
source "$(dirname "$0")/env.sh"
|
|
S="$ROOT/gatherers/src"; B="$ROOT/build/gatherers"; rm -rf "$B"; mkdir -p "$B"
|
|
|
|
"$JDK25/bin/javac" -d "$B" "$S"/*.java 2>&1 | grep -v -E '^(Note:|$)' || true
|
|
|
|
run() {
|
|
local outfile="$1" cls="$2"
|
|
{ echo "\$ java $cls (JDK 25)"; "$JDK25/bin/java" -cp "$B" "$cls" 2>&1; echo "exit=${PIPESTATUS[0]}"; } > "$OUT/$outfile" 2>&1
|
|
}
|
|
|
|
run 98-basics.txt GathererBasics
|
|
run 98-mapconcurrent.txt MapConcurrentDemo
|
|
run 98-custom-gatherer.txt CustomGatherer
|
|
run 98-collector-vs-gatherer.txt CollectorVsGatherer
|
|
|
|
echo "wrote $OUT/98-*.txt"
|