我正在使用Quartz每小时运行一次作业。该servlet在Tomcat上运行,我正在使用ServletConextListener来监听上下文被破坏的时间。

当我关闭tomcat时,我收到消息:

“似乎已启动名为[MyScheduler_Worker-1]的线程,但未能停止它”。

但是稍后我看到此消息:

“[DEBUG] 9月28日上午11:45:26.671 MyScheduler_Worker-1 [org.quartz.simpl.SimpleThreadPool]

WorkerThread已关闭。”

因此,可以安全地假设没有由于该线程导致的内存泄漏吗?

这是我的日志的样子:

{SEVERE: The web application [/*************] appears to have started a thread

named [MyScheduler_Worker-1] but has failed to stop it. This is very likely to c

reate a memory leak.

Sep 28, 2011 11:45:26 AM org.apache.catalina.loader.WebappClassLoader clearRefer

encesThreads

SEVERE: The web application [/*************] appears to have started a thread

named [MyScheduler_Worker-2] but has failed to stop it. This is very likely to c

reate a memory leak.

Sep 28, 2011 11:45:26 AM org.apache.catalina.loader.WebappClassLoader clearRefer

encesThreads

SEVERE: The web application [/*************] appears to have started a thread

named [MyScheduler_Worker-3] but has failed to stop it. This is very likely to c

reate a memory leak.

[DEBUG] 28 Sep 11:45:26.671 AM MyScheduler_Worker-2 [org.quartz.simpl.SimpleThre

adPool]

WorkerThread is shut down.



[DEBUG] 28 Sep 11:45:26.671 AM MyScheduler_Worker-1 [org.quartz.simpl.SimpleThre

adPool]

WorkerThread is shut down.



[DEBUG] 28 Sep 11:45:26.671 AM MyScheduler_Worker-3 [org.quartz.simpl.SimpleThre

adPool]

WorkerThread is shut down.

最佳答案

我知道这是一个旧线程,但万一其他人正在寻找它。

我们一直都在获取线程警告,直到在ServletContextListener.shutDown()方法中添加代码以关闭Quartz Scheduler为止。

要关闭调度程序:

            quartzScheduler.shutdown();

            int ct = 0;

            // Try waiting for the scheduler to shutdown. Only wait 30 seconds.
            while(ct < 30) {
                ct++;
                // Sleep for a second so the quartz worker threads die.  This
                // suppresses a warning from Tomcat during shutdown.
                Thread.sleep(1000);
                if (quartzScheduler.isShutdown()) {
                    break;
                }
            }

关于tomcat - quartz : Memory Leak?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7586255/

10-13 00:02