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

来源:互联网 发布:查看网络攻击的网站 编辑:程序博客网 时间:2024/06/02 19:01

 The web application [] appears to have started ...
  • 发布时间: 2012/07/25 11:51 
  • 阅读: 468 
  • 收藏: 0 
  • 点赞: 0 
  • 评论: 0

    有看到过这个标题的人吗?我的Tomcat出什么问题了?

    有一个servlet,它在init方法里面实例化了一个线程类。这个类里面启动了若干个daemon线程。

    有一个listener,它在contextDestroyed方法里面关闭这个线程类。

    在catalina.out里面出现了这样的日志。

    在下面的这个link里面,apache官方给了一些说明:

    http://wiki.apache.org/tomcat/MemoryLeakProtection

    其中就包含了这种问题。具体的原因说的很清楚:

    

 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的引用指向到里我的线程类。

    修改方法参照官方说明。

    

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方法。
0 0
原创粉丝点击