Since Log4j must support JDK1.4 (actually, still 1.3, I believe), I don't see how we could use JDK1.5+ ThreadLocal.remove()?

That said, there are other ways of cleaning up ThreadLocals that don't require remove().  For examples, see CrazyBob's "Hard Core Java: ThreadLocal" from back in 2006 [1].  Log4j could utilize CrazyBob's suggestions and provide an MDC cleanup method to allow users a chance to clean up.  Thoughts?

Also, for reference, I thought I'd provide a link to what the commons-lang guys did to fix their memory leaks, though keep in mind it depends on the JDK1.5+ ThreadLocal.remove() method [2].  They also use a WeakHashMap, which I'm not sure is necessary or not for Log4j's purposes?


[1] http://blog.crazybob.org/2006/07/hard-core-java-threadlocal.html
[2] https://fisheye6.atlassian.com/browse/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/ToStringStyle.java#r907126

Jake

On Fri, 24 Sep 2010 09:24:10 +0200
 Marcel Stör <mar...@frightanic.com> wrote:
The initial problem description was sent to the users list: http://www.mail-archive.com/log4j-u...@logging.apache.org/msg11921.html

However, I think it actually belongs here...

I believe that the MDC should provide a method that internally calls ThreadLocal#remove which was added to the API with Java5:
http://download.oracle.com/javase/6/docs/api/java/lang/ThreadLocal.html#remove%28%29

Other libraries/frameworks start fixing their issues with this, too:
- https://issues.apache.org/jira/browse/LANG-586
- https://jira.springsource.org/browse/SPR-7441
- https://jira.springsource.org/browse/SEC-1578

Regards,
Marcel

P.S. I'm using the slf4j MDC but AFAIK it simply delegates to log4j.

--
Marcel Stör, http://www.frightanic.com
Couchsurfing: http://www.couchsurfing.com/people/marcelstoer
O< ascii ribbon campaign - stop html mail - www.asciiribbon.org

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




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

Reply via email to