https://issues.apache.org/bugzilla/show_bug.cgi?id=50486

--- Comment #41 from smarkwal <[email protected]> ---
(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: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to