Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8286667

Implementation of Scoped values (Incubator)

    XMLWordPrintable

Details

    • CSR
    • Resolution: Approved
    • P3
    • 20
    • core-libs
    • None
    • minimal
    • New API in incubator module, no compatibility impact.
    • Java API
    • JDK

    Description

      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. This is an incubating API.

      Problem

      The Motivation section in the JEP explains some of the problems with the design of thread-local variables. These include unconstrained mutability, unbounded persistence, and expensive inheritance. These problems become more pressing in the context of virtual threads (JEP 425).

      Solution

      ScopedValue that is a value that is set once and is then available for reading for a bounded period of execution by a thread. The API is in an incubator module, the module and package name is jdk.incubator.concurrent so it is co-located with StructuredTaskScope (JEP 428). The new classes are:

      jdk.incubator.concurrent.ScopedValue
      jdk.incubator.concurrent.ScopedValue.Carrier

      The javadoc for the existing jdk.incubator.concurrent.StructuredTaskScope is updated to specify the inheritance of scoped value into child threads.

      Specification

      Attached is the javadoc for the jdk.incubator.concurrent module, and specdiffs that show the changes from JDK 19.

      Attachments

        Issue Links

          Activity

            People

              aph Andrew Haley
              alanb Alan Bateman
              Alan Bateman
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: