有看到過這個標題的人嗎?個人Tomcat出什麼問題了?java
有一個servlet,它在init方法裏面實例化了一個線程類。這個類裏面啓動了若干個daemon線程。web
有一個listener,它在contextDestroyed方法裏面關閉這個線程類。apache
在catalina.out裏面出現了這樣的日誌。tomcat
在下面的這個link裏面,apache官方給了一些說明:app
http://wiki.apache.org/tomcat/MemoryLeakProtectionwebapp
其中就包含了這種問題。具體的緣由說的很清楚:ide
Here, when the app is stopped, the webapp classloader is still referenced by the spawned thread both through its context classloader and its current call stack (the anonymous Thread subclass is loaded by the webapp classloader). When stopping an application, tomcat checks the context classloader of every Thread, and if it is the same as the app being stopped, it logs the following message :
當前app的classloader的引用指向到裏個人線程類。spa
修改方法參照官方說明。線程
leakingThread.setContextClassLoader(null)
還有另一種修改方法。日誌
在咱們的線程類裏面加入stop方法:
class Example implements Runnable { private volatile boolean isStop; private Thread runThread; @Override public void run() { runThread = Thread.currentThread(); isStop = false; while(!isStop){ try { process(); } catch (XMPPException e) { log.error("Example logic exception.", e); } } } public void stopRun() { isStop = true; if(runThread != null) { runThread.interrupt(); } }而後在contextDestroyed方法裏面調用stopRun方法。