logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christian Grobmeier <grobme...@gmail.com>
Subject Re: [Bug 50486] Memoryleak - org.apache.log4j.helpers.ThreadLocalMap
Date Wed, 30 May 2012 06:36:13 GMT
On Wed, May 30, 2012 at 7:59 AM, Ralph Goers <ralph.goers@dslextreme.com> wrote:
> As I see it, the problem is that at least some of the users seem to be
> expecting Log4j to magically know when to call clear. It can't. The
> application has to do it.
>
> All the MDC is is a ThreadLocal where each Thread has its own Map associated
> with the ThreadLocal. You can get and put all you want. In a webapp, of
> course, if you add stuff to the MDC at the beginning of a request then you
> need to remove it all at the end of the request.  The normal pattern is
>
> MDC.put(key, value);
> try {
>    call servlet
> } finally {
>   MDC.remove(key);
> }
>
> The problem with this is that it still leaves an empty Map in the
> ThreadLocal. So when remove() removes the last element from the Map then the
> Map is removed from the ThreadLocal.

OK understood. But actually isn't this happening with this fix?
in remove0(key): if table isEmpty ->  call clear0()
In clear(): tlm.remove

>From what I understood now we are doing what we can do. Except, we can
provide a FAQ description.

> FWIW, Logback suffered a similar issue
> in http://jira.qos.ch/browse/LBCLASSIC-183.

Thank you. Interesting read. It seems one can only have a comfortable
"fix" with Java > 5

Cheers
Christian

> Ralph
>
>
> On May 29, 2012, at 10:31 PM, Christian Grobmeier wrote:
>
> Bringing this to the mailinglist.
>
> Ralph, I understand what you explained below, but I am lost on how to
> fix it. Do you have any more suggestions?
> I must actually admit that I am not familiar with MDC at all, probably
> that's my problem with it.
>
> On Wed, May 30, 2012 at 7:26 AM,  <bugzilla@apache.org> wrote:
>
> https://issues.apache.org/bugzilla/show_bug.cgi?id=50486
>
>
> --- Comment #37 from Ralph Goers <Ralph.Goers@dslextreme.com> ---
>
> Yes, that is what clear is for.
>
>
> I don't see how Hierarchy.shutdown() can call MDC.clear(). Well, it could
> but
>
> it would only clear the thread the shutdown is performed on which isn't
> likely
>
> to help much.
>
>
> Item 2 is likely to cause many problems.  MDC.clear only clears the current
>
> thread's ThreadLocal. Reinitializing the MDC will cause problems for all the
>
> other threads.
>
>
> --
>
> You are receiving this mail because:
>
> You are the assignee for the bug.
>
>
> ---------------------------------------------------------------------
>
> To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
>
> For additional commands, e-mail: log4j-dev-help@logging.apache.org
>
>
>
>
>
> --
> http://www.grobmeier.de
> https://www.timeandbill.de
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-dev-help@logging.apache.org
>
>



-- 
http://www.grobmeier.de
https://www.timeandbill.de

---------------------------------------------------------------------
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