ppkarwasz commented on issue #2499:
URL: 
https://github.com/apache/logging-log4j2/issues/2499#issuecomment-2079311501

   > @ppkarwasz, this is the core problem this problem is attacking to, right? 
That is, avoiding redundant propagation when a particular bridge is in play.
   
   Yes, my main motivation is to reduce the overhead of context propagation. 
See also the discussion at micrometer-metrics/context-propagation#108.
   
   Unfortunately I don't think we can implement these changes by default, since 
I found examples of **legitimate** usages of `ThreadContext` accessors. E.g.:
   
   ```java
   Map<String, String> oldMap = ThreadContext.getImmutableMapOrNull();
   try {
       ThreadContext.put("key", "value");
       ...
   } finally {
       ThreadContext.clear();
       if (oldMap != null) {
           ThreadContext.putAll(oldMap);
       }
   }
   ```
   
   or 
   
   ```java
   String oldValue = ThreadContext.get("key");
   try {
       ThreadContext.put("key", "value");
       ...
   } finally {
       if (oldValue == null) {
           ThreadContext.remove("key");
       } else {
           ThreadContext.put("key", oldValue);
       }
   }
   ```
   
   `ThreadContext` API users unfortunately **must** use accessors or need to 
switch to `CloseableThreadContext`.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to