title: java.lang.IllegalStateException: Timer already cancelled when webapp redeploys on tomcat
body: <p>Using Hibernate in a struts2 webapp when the application redeploys I get this error when trying to access pages after redeploy.</p>
  
  <pre><code>java.lang.IllegalStateException: Timer already cancelled.
  </code></pre>
  
  <p>Just after redeploy tomcat logs the following output which indicates the cause of the problem is that Hibernate is not shutting down properly when the first instance of the webapp is shutdown.</p>
  
  <pre><code>Oct 15, 2010 8:58:34 PM org.apache.catalina.loader.WebappClassLoader clearReferencesStopTimerThread
  SEVERE: A web application appears to have started a TimerThread named [Timer-0] 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. 
  </code></pre>
  
  <p>I have added a ContextListener which with the following in the contextDestroyed method but this has had no effect.</p>
  
  <pre><code>@Override
  public void contextDestroyed(ServletContextEvent arg0) {
  
      HibernateUtil.getSessionFactory().close();
  
  }
  </code></pre>
  
  <p>Is there anything else I can do to prevent this error?</p>