Paul Krill
Editor at Large

Proposed Java API would enable sharing of immutable data across threads

news
Sep 12, 20222 mins

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
Credit: 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.

Paul Krill

Paul Krill is editor at large at InfoWorld. Paul has been covering computer technology as a news and feature reporter for more than 35 years, including 30 years at InfoWorld. He has specialized in coverage of software development tools and technologies since the 1990s, and he continues to lead InfoWorld’s news coverage of software development platforms including Java and .NET and programming languages including JavaScript, TypeScript, PHP, Python, Ruby, Rust, and Go. Long trusted as a reporter who prioritizes accuracy, integrity, and the best interests of readers, Paul is sought out by technology companies and industry organizations who want to reach InfoWorld’s audience of software developers and other information technology professionals. Paul has won a “Best Technology News Coverage” award from IDG.

More from this author