The web application [] appears to have started ...

    有看到过这个标题的人吗?个人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方法。
相关文章
相关标签/搜索