Can DefaultThreadContextMap be modified to avoid creating a new instance with each update? #3032
Replies: 2 comments 4 replies
-
Hi @wang-qijia, The If you want to limit the number of allocations, you can use methods such as If you want to remove the allocation entirely and you are not using a Servlet Container, you can switch to a garbage-free implementation as described in garbage-free logging by setting the Note: The garbage-free |
Beta Was this translation helpful? Give feedback.
-
@wang-qijia, I tend to agree with you. I think the default Thread Context implementation can (and should?) do better – see my comments here. I intend to submit a PR to improve the situation. |
Beta Was this translation helpful? Give feedback.
-
If the client calls MDC.put() 10 times, the current implementation creates 10 maps, resulting in frequent memory allocations. Is it possible to modify this so that put does not create a new map, and enhance getImmutableMapOrNull to return a decorated immutable version of the original map?
Beta Was this translation helpful? Give feedback.
All reactions