Quartz : Memory Leak?

非 Y 不嫁゛ 提交于 2020-08-19 04:27:09

问题


I am using Quartz to run a job every hour. The servlet is running on Tomcat and I am using the ServletConextListener to listen for when the context is destroyed.

When I shut down tomcat, I get the message:

"appears to have started a thread named [MyScheduler_Worker-1] but has failed to stop it".

But later I see this message:

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

WorkerThread is shut down."

So is it safe to assume that there is no memory leak because of this thread?

Here is how my log looks:

{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.

回答1:


I know this is an old thread but in case others are looking for it.

We use to get the warnings of threads all the time until we added code to shutdown the Quartz Scheduler in our ServletContextListener.shutDown() method.

To shutdown the 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;
                }
            }



回答2:


You can assume there is no memory leak because you see thread shutdown message. However, its possible to over come warning by clearing up threads before shut-down.

The shutdown-hook plugin catches the event of the JVM terminating, and calls shutdown on the scheduler.

Details:- http://quartz-scheduler.org/documentation/quartz-2.x/configuration/ConfigPlugins



来源:https://stackoverflow.com/questions/7586255/quartz-memory-leak

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!