[
https://issues.apache.org/jira/browse/LOG4J2-1349?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15349650#comment-15349650
]
Remko Popma commented on LOG4J2-1349:
-------------------------------------
I just realized that creating a garbage-free implementation of the
{{org.apache.logging.log4j.spi.ThreadContextMap}} service provider interface is
one thing, but getting data out of this data structure without creating garbage
is another thing.
Currently the {{ThreadContext}} API does not give access to the underlying
ThreadContextMap, but I think we need it to get the key-value pairs from the
context into the LogEvents without creating garbage. (The existing methods
ThreadContext.getContext() and ThreadContext.getImmutableContext() return a
java.util.Map, which cannot be queried without creating garbage.)
I propose we add a method {{getThreadContextMap() : ThreadContextMap}} to
ThreadContext.
> Garbage-free ThreadContext map
> ------------------------------
>
> Key: LOG4J2-1349
> URL: https://issues.apache.org/jira/browse/LOG4J2-1349
> Project: Log4j 2
> Issue Type: Improvement
> Components: API
> Affects Versions: 2.5
> Reporter: Remko Popma
> Assignee: Remko Popma
> Fix For: 2.7
>
>
> The current ThreadContext map and stack implementations allocate temporary
> objects. This ticket is to investigate and track the work for alternative
> implementations that are garbage-free.
> Both DefaultThreadContextMap and DefaultThreadContextStack are copy-on-write
> data structures: each modification replaces the ThreadLocal object with a
> modified copy. The advantage of this approach is that there is no need to
> make a copy for each LogEvent.
> Also, DefaultThreadContextMap uses a JDK map, the JDK collections tend to
> allocate a lot of temporary objects.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]