错误示例:
严重: The web application [/flex_vod] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@793ae954]) and a value of type [flex.messaging.client.FlexClient] (value [flex.messaging.client.FlexClient@2f35d7ad]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.
2011-3-16 10:40:26 org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
部分描述:
The leak is caused because we have a custom class for the ThreadLocal instance, and also a custom class for the value bound to the Thread. Actually the important thing is that both classes were loaded by the webapp classloader.
Hopefully tomcat 6.0.24 can detect the leak when the application is stopped: each Thread in the JVM is examined, and the internal structures of the Thread and ThreadLocal classes are introspected to see if either the ThreadLocal instance or the value bound to it were loaded by the WebAppClassLoader of the application being stopped.
In this particular case, the leak is detected and a message is logged. Tomcat 6.0.24 to 6.0.26 modify internal structures of the JDK (ThreadLocalMap) to remove the reference to the ThreadLocal instance, but this is unsafe (see #48895) so that it became optional and disabled by default from 6.0.27. Starting with Tomcat 7.0.6, the threads of the pool are renewed so that the leak is safely fixed.