logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject [Bug 50486] Memoryleak - org.apache.log4j.helpers.ThreadLocalMap
Date Wed, 30 May 2012 07:13:01 GMT
https://issues.apache.org/bugzilla/show_bug.cgi?id=50486

--- Comment #41 from smarkwal <stephan.markwalder@appway.com> ---
(In reply to comment #38)
> [...] In a servlet environment, you might want to put
> this code into the Servlet.destroy() method:

I don't think that calling the clear method in the servlet's destroy method
does the job. The destroy method may be invoked by a background thread of the
application server and would remove the ThreadLocal value only from this
background thread, not form the HTTP worker threads.

I agree with Marcel that a servlet filter is the best option:

public class ClearMDCFilter implements Filter {

    @Override
    public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
        try {
            chain.doFilter(request, response);
        } finally {
            MDC.clear();
        }
    }

    [...]

}

This way, you don't have to care about removing all keys you set somewhere in
your code.

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


Mime
View raw message