您的位置:首页 > 大数据 > 人工智能

failed to remove it when the web application was stopped. Threads are going to be renewed over time

2017-03-17 21:11 1026 查看
该error的原因:

 tomcat关闭应用时的清理工作(3): ThreadLocal

这个泄露其实是可能造成classloader的泄露,因为
ThreadLocal
引用了自定义的类
MyClass
,绑定到了当前的请求线程上,而请求线程又是线程池里的线程,生存周期可能会比较长。比如上面模拟的情况,要停止应用的时候,请求线程的
ThreadLocal
仍未释放,那么即使加载
MyClass
类的classLoader已经不会再被任何地方使用,可以被垃圾回收了,却因为这个
MyClass
被引用而得不到回收。

解决方案:

private static ThreadLocal<MyClass> tl = new ThreadLocal<MyClass>();

try{
// doSomething()
} finally {
tl.remove();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐