Tomcat >=6.0.24 comes with a pre-configured "memory leak detection" listener
that cleans up when an application is shutdown.
It particularly complains about ThreadLocal in log4j's MDC (many such log
statements):
A web application created a ThreadLocal with key of type
[org.apache.log4j.helpers.ThreadLocalMap] (value
[org.apache.log4j.helpers.threadlocal...@5212bc]) and a value of type
[java.util.Hashtable] (value [{}]) but failed to remove it when the web
application was stopped. To prevent a memory leak, the ThreadLocal has been
forcibly removed.
One can see that the Hashtable in the ThreadLocal is empty but that doesn't
seem to be enough as the ThreadLocal itself is not empty....
I'm using the MDC in a ServletContextFilter like so:
try {
if (request instanceof HttpServletRequest) {
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
Principal principal = httpServletRequest.getUserPrincipal();
if (principal != null) {
MDC.put(MDC_PRINCIPAL_KEY, principal.getName());
}
}
chain.doFilter(request, response);
} finally {
MDC.remove(MDC_PRINCIPAL_KEY);
}
Do I have a chance to properly clear the ThreadLocal variable?
Regards,
Marcel
--
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: [email protected]
For additional commands, e-mail: [email protected]