views:

111

answers:

2

Hi all,

for my webapp I use Quartz. When I deploy the app all is ok. When I undeploy the app more Quartz's process don't be destroied.

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

+2  A: 

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.

matt b
Yes, my app use quartz for execute thread in a given moment of the day.
tommaso
@tommaso I was asking how you start/invoke the Quartz scheduler to be able to execute jobs at specific times. Given that you are in a servlet environment, rather than simply starting it in your code you likely want to hook into the listener/servlet startup sequence, so you can also receive notification when the application is being shut down - so you can shut down quartz at the same time.
matt b
I give to spring the control of quartz via org.springframework.scheduling.quartz.SchedulerFactoryBean<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean" destroy-method="destroy"> <property name="triggers"> <list> <ref bean="cronTrigger"/> </list> </property><property name="quartzProperties"> <props><prop key="org.quartz.threadPool.class">org.quartz.simpl.SimpleThreadPool</prop>...</props></property></bean>
tommaso
And how are you initializing/starting Spring? Is it through a ContextLoaderListener? Is Spring notified when the app shuts down?
matt b
Yes spring start via ContextLoaderListener and Spring received a notify when the app shut down.
tommaso
The `destroy()` method of `SchedulerFactoryBean` will invoke `org.quartz.Scheduler.shutdown()` with a boolean argument for `waitForJobsToCompleteOnShutdown`. Are you by any chance setting this flag in `SchedulerFactoryBean` to true? Perhaps Tomcat does not wait long enough for jobs to complete in Quartz before shutting down anyway.
matt b
This parameter is set to true, but after still waiting more than 2 minutes tomcat not stop.
tommaso
Well are your jobs completing within that time frame or are they longer-running? Do you need the server shutdown to wait for the jobs to complete? Sounds like you need to choose between one or the other.
matt b
A: 

Hi Matt,

Could you please expand a bit more? Do you mean the webapp's web.xml or tomcat6's web.xml? also the server.xml has some settings on the listeners.

Thanks for that,

MRM
edited my answer above to answer your question
matt b
I think you would like to put it to your web.xmlhttp://java.sun.com/developer/technicalArticles/Servlets/servletapi2.3/ there is more about listeners.
Joni
MRM