JEP 506: Scoped Values final for Java 25
Published on: 2025-04-27 13:17:02
Summary
Introduce scoped values, which enable a method to share immutable data both with its callees within a thread, and with child threads. Scoped values are easier to reason about than thread-local variables. They also have lower space and time costs, especially when used together with virtual threads (JEP 444) and structured concurrency (JEP 505).
History
The scoped values API was proposed for incubation by JEP 429 (JDK 20), proposed for preview by JEP 446 (JDK 21), and subsequently improved and refined by JEP 464 (JDK 22), JEP 481 (JDK 23), and JEP 487 (JDK 24).
We here propose to finalize the scoped values API in JDK 25, without further change.
Goals
Ease of use — It should be easy to reason about dataflow.
Comprehensibility — The lifetime of shared data should be apparent from the syntactic structure of code.
Robustness — Data shared by a caller should be retrievable only by legitimate callees.
Performance — Data should be efficiently sharable across a large number of t
... Read full article.