<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    On 31/10/2022 20:48, Volkan Yazıcı wrote:<br>
    <blockquote type="cite" cite="mid:CABDM8gBNir3Snso1P5podWFxWt=D87HUWGL-NJuhr4HMVrpx+Q@mail.gmail.com">
      
      <div dir="ltr">
        <div>Below is a list of TL usages in the Log4j code base. Note
          that some serve other purposes than object pooling, yet I
          wanted to share them anyway for completeness.</div>
        <br>
        <div>- Log `Message`s and `LogEvent`s – all `<a href="https://urldefense.com/v3/__http://log.info__;!!ACWV5N9M2RV99hQ!OqcqqIuxZfWxWBhWsDZzPFYspDFPSQtFJtbMBN-kTfQJKLcl3c_ngGsOanxY0iQgfz-oFogKSZ9WaVo6eg$" target="_blank" moz-do-not-send="true">log.info</a>()` calls
          get converted into a `LogEvent` wrapping a `Message`</div>
        <div><br>
        </div>
        <div>- Context Stack and Context Data (aka. NDC and MDC) stacks
          and lists, respectively. TLs, besides providing an efficient
          way to mutate these data structures, also serve another
          important purpose: storing the logging context along the
          lifetime of an _operation_, which can be an HTTP
          request-response, database transaction, etc. Ideally, these
          should all be replaced with dynamic/scoped variables.
          Nevertheless, there will (might?) be still a need for object
          pooling to avoid instantiating a new MDC/NDC each time. Though
          this can be efficiently implemented without needing TLs.<br>
        </div>
      </div>
    </blockquote>
    <br>
    Scoped values are all about reading a value in a bounded period of
    execution by a thread so it would be good to try it with these
    examples. That said, you say "mutate these data structures" whereas
    the value of a ScopedValue should really be immutable and
    thread-safe, esp. when a task using scoped values is refactored into
    concurrent subtasks.<br>
    <br>
    <br>
    <blockquote type="cite" cite="mid:CABDM8gBNir3Snso1P5podWFxWt=D87HUWGL-NJuhr4HMVrpx+Q@mail.gmail.com">
      <div dir="ltr">
        <div><br>
        </div>
        <div>- `StringBuilder`s – used in various layout implementations
          for encoding the user input into a `ByteBuffer`. The user
          input is first written to a `StringBuilder`, then the
          `StringBuilder#getChars()` is used to dump its contents to a
          `ByteBuffer`, and finally a `CharsetEncoder` is used to encode
          these characters to another target `ByteBuffer`[1]. As you
          might guess, both the input and the output `ByteBuffer`s are
          also received from TLs.</div>
      </div>
    </blockquote>
    Assuming these aren't direct buffers, it would be useful to see if
    this caching has a positive or negative impact when using recent JDK
    releases.<br>
    <br>
    <blockquote type="cite" cite="mid:CABDM8gBNir3Snso1P5podWFxWt=D87HUWGL-NJuhr4HMVrpx+Q@mail.gmail.com">
      <div dir="ltr">
        <div><br>
        </div>
        <div>- Recursion prevention and depth limiting – again, a use
          case that better be addressed with dynamic variables, though
          Java is not there yet.</div>
      </div>
    </blockquote>
    <br>
    Yes but only if there isn't any inheritance. Inheritance is an area
    of this API that needs more feedback.<br>
    <br>
    -Alan<br>
  </body>
</html>