ThreadLocal 引起的内存泄露
最近在用LOADRUNNER做性能测试,?
运行几个小时后,内存一直增加, 最后出现了内存OutMemory问题。?
?
已知的一个BUG:
http://java.net/jira/browse/JAXB-844
?
?
JAXB 2.1.15 有问题类Coordinator?
?
?
?
变量adapters一直没有进行REMOVE操作?
?
JAXB(V2.2.25)修复后的代码如下:
?
?
?
主要是加了下面这个代码修复了内存泄露问题
?
?
/** * Dis-associate this {@link Coordinator} with the current thread. * Sohuld be called at the end of the episode to avoid memory leak. */ protected final void resetThreadAffinity() { if (activeTable != null) { activeTable.remove(); } if(debugTableNPE) guyWhoSetTheTableToNull = new Exception(); // remember that we set it to null table = null; }?
所以由THREADLOCAL创建的变量一定要进行REMOVE操作
?
原文:http://extjs2.iteye.com/admin/blogs/1701172