This is the CSR for JEP 446: Scoped Values (Preview).
Summary
Introduce scoped values, which enable the sharing of immutable data within and across threads. They are preferred to thread-local variables, especially when using large numbers of virtual threads.
Problem
The motivation in the JEP explains the disadvantages of alternative approaches to Scoped Values at some length.
Solution
Add a simple API that allows the one-way transmission of data from caller to callees within the same dynamic scope. This scope is not just that of a single thread: it extends to allow scoped values in a parent thread to be automatically inherited by child threads created with StructuredTaskScope
.
The preview APIs proposed are:
java.lang.ScopedValue
java.lang.ScopedValue.Carrier
In conjunction with JEP 453, remove module jdk.incubator.concurrent.
Specification
The specdiffs are attached.
- csr of
-
JDK-8306572 Implementation of Scoped Values (Preview)
-
- Resolved
-
- relates to
-
JDK-8331190 Implementation of Scoped Values (Third Preview)
-
- Closed
-
- links to