title: How to prevent a memory leak in quartz
body: <p>I'm using quartz in my project. My web application has apparently caused a memory leak when it stops, the error is : </p>
  
  <pre><code>SEVERE: A web application appears to have started a TimerThread named [Timer-12] via the java.util.Timer API but has failed to stop it. To prevent a memory leak, the timer (and hence the associated thread) has been forcibly cancelled. 
  Jan 2, 2013 6:55:35 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
  SEVERE: A web application 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.
  </code></pre>
  
  <p>I used <code>org.quartz.ee.servlet.QuartzInitializerServlet</code> and <code>org.quartz.ee.servlet.QuartzInitializerListener</code>. The code for my factory is: </p>
  
  <pre><code>StdSchedulerFactory factory = (StdSchedulerFactory) context.getAttribute(QuartzInitializerListener.QUARTZ_FACTORY_KEY );
  </code></pre>
  
  <p>and settings for quartz in web.xml is : </p>
  
  <pre><code>&lt;servlet&gt;
           &lt;servlet-name&gt;
               QuartzInitializer
           &lt;/servlet-name&gt;
           &lt;display-name&gt;
               Quartz Initializer Servlet
           &lt;/display-name&gt;
           &lt;servlet-class&gt;
               org.quartz.ee.servlet.QuartzInitializerServlet
           &lt;/servlet-class&gt;
           &lt;load-on-startup&gt;
               1
           &lt;/load-on-startup&gt;
           &lt;init-param&gt;
               &lt;param-name&gt;shutdown-on-unload&lt;/param-name&gt;
               &lt;param-value&gt;true&lt;/param-value&gt;
           &lt;/init-param&gt;
           &lt;init-param&gt;
               &lt;param-name&gt;wait-on-shutdown&lt;/param-name&gt;
               &lt;param-value&gt;true&lt;/param-value&gt;
           &lt;/init-param&gt;
           &lt;init-param&gt;
               &lt;param-name&gt;start-scheduler-on-load&lt;/param-name&gt;
               &lt;param-value&gt;true&lt;/param-value&gt;
           &lt;/init-param&gt;
       &lt;/servlet&gt;
       &lt;context-param&gt;
           &lt;param-name&gt;quartz:shutdown-on-unload&lt;/param-name&gt;
           &lt;param-value&gt;true&lt;/param-value&gt;
       &lt;/context-param&gt;
       &lt;context-param&gt;
           &lt;param-name&gt;quartz:wait-on-shutdown&lt;/param-name&gt;
           &lt;param-value&gt;true&lt;/param-value&gt;
       &lt;/context-param&gt;
       &lt;context-param&gt;
           &lt;param-name&gt;quartz:start-on-load&lt;/param-name&gt;
           &lt;param-value&gt;true&lt;/param-value&gt;
       &lt;/context-param&gt;
       &lt;listener&gt;
           &lt;listener-class&gt;
               org.quartz.ee.servlet.QuartzInitializerListener
           &lt;/listener-class&gt;
       &lt;/listener&gt;
  </code></pre>
  
  <p>please help me to solve this memory leak !! </p>