ppkarwasz commented on PR #2438:
URL: https://github.com/apache/logging-log4j2/pull/2438#issuecomment-2038901414
> Looking a second time at your example I now see what you are attempting to
do but I don't think you even need to modify ThreadContextMap to do that. I
could just do:
>
> ```java
> Map<String, String> oldContext = ThreadContext.getContext();
> try {
> ThreadContext.clearMap();
> ThreadContext.putAll(newMap);
> op.run();
> } finally {
> ThreadContext.clearMap();
> ThreadContext.putAll(oldContext);
> }
> ```
Sure, this is possible without any changes to `ThreadContextMap`, but it is
not necessarily efficient: depending on the implementation it might need to
convert the internal representation to `Map` and create copies. Transferring
data between threads is a rare, but expensive operation, so we might consider
optimizing it.
--
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]