Get the latest tech news

JEP 506: Scoped Values final for Java 25


mmary 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.

The preferred mechanism for user code to create virtual threads is the Structured Concurrency API ( JEP 505), specifically the class StructuredTaskScope. However, carrying the additional baggage of thread-local variables results in an implementation that is unduly burdensome, or an API that returns UnsupportedOperationException for much of its core functionality, or both. We ultimately rejected that idea because it is impossible to guarantee correct operation when relying on user code to invoke the close method at the right time.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of JEP

JEP

Photo of Scoped Values

Scoped Values

Photo of Java 25

Java 25

Related news:

News photo

Let's Take a Look at JEP 483: Ahead-of-Time Class Loading and Linking

News photo

JEP 483: Ahead-of-Time Class Loading and Linking

News photo

JEP draft: Exception handling in switch