Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quartz scheduler in Tomcat 6, thread does not stop

for my webapp I use Quartz. When I deploy the app all is ok. When I undeploy the app, the Quartz thread is not destroyed.

Log is:

INFO: Stopping service Catalina

SEVERE: The web application [/example] appears to have started a thread named [DefaultQuartzScheduler_Worker-1] but has failed to stop it. This is very likely to create a memory leak. Jul 12, 2010 6:30:40 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads

Anyone can tell me how I can force the destroy action for those threads?

Thanks,

Tommaso

like image 728
Tommaso Taruffi Avatar asked Jul 12 '10 16:07

Tommaso Taruffi


2 Answers

I found that the issue for me was that quartz was being shutdown but the webapp didn't wait for quartz to finish before it shutdown so Tomcat decided that it had left threads running and complained.

So I managed my scheduler like this:

Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
...do some stuff with the scheduler...
scheduler.shutdown(true);

Note the boolean argument to shutdown is the vital part. If you remove that true to call the no-arg version or set it to false, your webapp won't wait for quartz to shudown before it shuts down.

TL;DR: call scheduler.shutdown(true) to make your webapp wait for quartz to finish.

like image 186
Tom Saleeba Avatar answered Oct 26 '22 14:10

Tom Saleeba


How are you starting Quartz?

Assuming you are not using a convenient wrapper like Spring, you probably want to be using a <listener> in your application's web.xml so that Quartz can be notified of the application start and shutdown.

See QuartzInitializerListener or QuartzInitializerServlet for instance.

like image 39
matt b Avatar answered Oct 26 '22 16:10

matt b