Proposed Java API would enable sharing of immutable data across threads

Extent-local variables would provide a way to share data both within a thread and with child threads in Java, making it easier to reason about data flow.

data flow
Dell Technologies

Java could gain a capability for sharing immutable data across threads, based on a plan now under consideration in the OpenJDK realm.

An OpenJDK proposal for extent-local variables, currently an incubating API, would provide a programming model to share data both within a thread and with child threads. Extent-local variables are preferred to thread-local variables, particularly when using large numbers of virtual threads, the proposal states.

The proposal lists four goals behind the incubating API:

  • Ease of use, to simplify reasoning about data flow.
  • Comprehensibility, to make the lifetime of shared data visible from the syntactic structure of code.
  • Robustness, to ensure that data shared by a caller can be retrieved only by legitimate callees.
  • Performance, to treat shared data as immutable to allow sharing by a large number of threads and enable runtime optimizations.

The extent local-variables API currently is not slated for any particular version of standard Java. The earliest it could potentially appear would be in Java 20, due in March 2023. Java 19, or Java Development Kit 19, due to arrive on September 20, is closed to new features.

The extent-local variables plan does not involve changing the Java programming language itself. There also is no intent to require migration away from thread-local variables, or to deprecate the existing ThreadLocal API.

Copyright © 2022 IDG Communications, Inc.

How to choose a low-code development platform