Why it matters

ThreadLocal has issues with virtual threads. ScopedValue solves. Understanding shapes modern Java concurrency.

Advertisement

The architecture

ScopedValue.where(sv, value).run(runnable).

Value visible in runnable scope; hidden outside.

ScopedValue flowBind valuein scopeRun blockvalue visibleAuto-cleanupon scope exitImmutable + scope-based; auto-cleaned; virtual-thread friendly
ScopedValue usage.
Advertisement

How it works end to end

Immutable: unlike ThreadLocal, value can't change within scope.

Structured: naturally aligned with structured concurrency.

Performance: no leaks; no synchronization.