Java could gain the ability to share immutable data between threads, based on a plan currently being explored in the OpenJDK realm.
An OpenJDK proposal for scope local variables, currently an incubating API, would provide a programming model for sharing data both within a thread and with child threads. Scope-local variables are preferred over thread-local variables, especially when using a large number of virtual threads, the proposal states.
The proposal lists four goals behind the Incubation API:
- Ease of use, to simplify reasoning about data flows.
- Comprehensibility, to make visible the lifetime of shared data from the syntactic structure of the code.
- Robustness, to ensure that data shared by a caller can only be retrieved by legitimate callers.
- Performance, to treat shared data as immutable to allow sharing by a large number of threads and allow runtime optimizations.
The Local Variables Scope API is currently not intended for any particular version of standard Java. The earliest it could potentially appear would be in Java 20, scheduled for March 2023. Java 19, or Java Development Kit 19, is expected to arrive on September 20is closed to new features.
The plan for scope locals does not involve changing the Java programming language itself. There is also no intention to require migration from thread-local variables or to deprecate the existing ThreadLocal API.
Copyright © 2022 IDG Communications, Inc.