<html><head></head><body><div class="ydp46a41b9eyahoo-style-wrap" style="font-size: 13px; font-family: Helvetica Neue, Helvetica, Arial, sans-serif;"><div style=""><div dir="ltr" data-setdir="false" style="font-family: Helvetica Neue, Helvetica, Arial, sans-serif;">Thanks Alan.  Thinking about ScopedValue as an implicit parameter is a good insight. Also - the javadoc for the SopedValue does clarify a great deal about using with StructuredTaskScope. Thanks for pointing me to that. </div><div dir="ltr" data-setdir="false" style="font-family: Helvetica Neue, Helvetica, Arial, sans-serif;"><br></div><div dir="ltr" data-setdir="false" style="">As I was reading the ScopedValue Javadoc, I had another question. As part of the API note - the Javadoc says the following about Thread locals.</div><div dir="ltr" data-setdir="false" style=""><br></div><div dir="ltr" data-setdir="false" style="">"<a href="https://download.java.net/java/early_access/jdk21/docs/api/java.base/java/lang/InheritableThreadLocal.html" title="class in java.lang" rel="nofollow" target="_blank" style="font-size: 14px;">Inheritance</a><span style="color: rgb(53, 56, 51); font-size: 14px;"> is expensive - the map of thread-locals to values must be copied when creating each child thread."</span><span style="color: rgb(53, 56, 51); font-size: 14px;"> </span></div><div dir="ltr" data-setdir="false" style=""><span style="color: rgb(53, 56, 51); font-size: 14px;"><br></span></div><div dir="ltr" data-setdir="false" style=""><span style="color: rgb(53, 56, 51); font-size: 14px;">I assume this is referring to InheritableThreadLocals and not the regular ThreadLocals. My understanding is that the regular ThreadLocal objects don't get copied over to child threads </span></div><div class="ydp46a41b9esignature" style="font-family: Helvetica Neue, Helvetica, Arial, sans-serif;"><div> </div></div></div>
        <div style="font-family: Helvetica Neue, Helvetica, Arial, sans-serif;"><br></div><div style="font-family: Helvetica Neue, Helvetica, Arial, sans-serif;" dir="ltr" data-setdir="false">~ Viraj </div><div style="font-family: Helvetica Neue, Helvetica, Arial, sans-serif;"><br></div>
        
        </div><div id="yahoo_quoted_9971899166" class="yahoo_quoted">
            <div style="font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:13px;color:#26282a;">
                
                <div>
                    On Monday, July 17, 2023 at 03:40:35 AM EDT, Alan Bateman <alan.bateman@oracle.com> wrote:
                </div>
                <div><br></div>
                <div><br></div>
                <div><div id="yiv2645829679"><div>
    On 16/07/2023 23:30, viraj shetty wrote:<br clear="none">
    <blockquote type="cite">
      
      <div style="font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:13px;" class="yiv2645829679ydp561c10b5yahoo-style-wrap">
        <div dir="ltr">I have read JEP 446 related
          to Scoped Values and have been playing with it using Java 21
          early release. I have couple of minor
          questions/clarifications. </div>
        <div dir="ltr"><br clear="none">
        </div>
        <div dir="ltr">1. The JEP seems to convey
          the idea that the ScopeValue objects are one way communication
          down the call chain. But the scoped value can be an object
          which is mutable and it could be modified deep inside the call
          stack. Effectively that is two way communication - even though
          the variable itself cannot be modified. Not a big deal but
          maybe a clarification is useful</div>
      </div>
    </blockquote>
    <br clear="none">
    It's not too different to method parameters. Call a method with a
    mutable object as a method parameter and the callee may modify it.
    If you think of a ScopedValue object as an implicit method
    parameter, and the callee has access to to it, then it can also
    modify it.<br clear="none">
    <br clear="none">
    <br clear="none">
    <blockquote type="cite">
      <div style="font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:13px;" class="yiv2645829679ydp561c10b5yahoo-style-wrap">
        <div dir="ltr"><br clear="none">
        </div>
        <div dir="ltr">2. It also conveyed the idea
          that scoped values are automatically available for Child
          Threads. But on playing with it, its available only for child
          threads of StructuredTaskScope, not for threads started with
          Thread.ofVirtual() or Executorservice.  Is this because its
          guaranteed that the threads submitted in structuredTaskScope
          ends before ScopedValue scope ends ? Making it bounded is the
          idea ? </div>
        <br clear="none">
      </div>
    </blockquote>
    There is effort under way to improve the JEP text and how this
    feature is presented. In the case of inheritance then it will be
    clear that it's for structured contexts only. The API docs [1] try
    to make this clear. There is no equivalent for unstructured use as
    it would be the equivalent of accessing something after it has gone
    out of scope.<br clear="none">
    <br clear="none">
    -Alan<div id="yiv2645829679yqtfd22967" class="yiv2645829679yqt4793017357"><br clear="none">
    <br clear="none">
    [1]
</div><a rel="nofollow noopener noreferrer" shape="rect" target="_blank" href="https://download.java.net/java/early_access/jdk21/docs/api/java.base/java/lang/ScopedValue.html" class="yiv2645829679moz-txt-link-freetext">https://download.java.net/java/early_access/jdk21/docs/api/java.base/java/lang/ScopedValue.html</a><div id="yiv2645829679yqtfd00099" class="yiv2645829679yqt4793017357"><br clear="none">
  </div></div></div></div>
            </div>
        </div></body></html>