logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Remko Popma (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (LOG4J2-1142) ThreadLocals in Layout implementations should be non-static to prevent memory leaks in web containers
Date Wed, 30 Sep 2015 22:40:06 GMT

    [ https://issues.apache.org/jira/browse/LOG4J2-1142?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14938991#comment-14938991
] 

Remko Popma commented on LOG4J2-1142:
-------------------------------------

Ralph, it may be possible. The pool would have to be thread-safe though and using it would
need to be faster than creating a new StringBuilder (or there is no point).

It does seem that making the ThreadLocal field non-static would be much simpler. 

Another idea is to use the Strategy pattern here again and create a new StringBuilder instance
per log event for web applications and use a ThreadLocal otherwise. I prefer this to the pool
(which I suspect will bring its own complications).

> ThreadLocals in Layout implementations should be non-static to prevent memory leaks in
web containers
> -----------------------------------------------------------------------------------------------------
>
>                 Key: LOG4J2-1142
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1142
>             Project: Log4j 2
>          Issue Type: Improvement
>          Components: Layouts
>    Affects Versions: 2.4
>            Reporter: Dmitri Blinov
>            Assignee: Remko Popma
>             Fix For: 2.4.1
>
>
> As discussed in LOG4J2-1125, storing ThreadLocal<StringBuilder> in a static field
may not interact well with the thread pools and class loaders of some web containers and may
result in memory leaks, especially in older web containers.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Mime
View raw message