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

Implementation of Scoped Values (Preview)

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 21
    • core-libs
    • None
    • minimal
    • Hide
      Developers using the incubator API will need some code and command line changes to use the preview API.

      The java.lang package is implicitly imported on demand so adding anything to java.lang may be a source incompatible change. We aren't expecting any issues with the name "ScopedValue".
      Show
      Developers using the incubator API will need some code and command line changes to use the preview API. The java.lang package is implicitly imported on demand so adding anything to java.lang may be a source incompatible change. We aren't expecting any issues with the name "ScopedValue".
    • Java API
    • SE

      This is the CSR for JEP 446: Scoped Values (Preview).

      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.

      Problem

      The motivation in the JEP explains the disadvantages of alternative approaches to Scoped Values at some length.

      Solution

      Add a simple API that allows the one-way transmission of data from caller to callees within the same dynamic scope. This scope is not just that of a single thread: it extends to allow scoped values in a parent thread to be automatically inherited by child threads created with StructuredTaskScope.

      The preview APIs proposed are:

      java.lang.ScopedValue
      java.lang.ScopedValue.Carrier

      In conjunction with JEP 453, remove module jdk.incubator.concurrent.

      Specification

      The specdiffs are attached.

            aph Andrew Haley
            aph Andrew Haley
            Alan Bateman, Paul Sandoz
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: