views:

53

answers:

1

Hi,

Using Hibernate in a struts2 webapp when the application redeploys I get this error when trying to access pages after redeploy.

java.lang.IllegalStateException: Timer already cancelled.

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.

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. 

I have added a ContextListener which with the following in the contextDestroyed method but this has had no effect.

@Override
public void contextDestroyed(ServletContextEvent arg0) {

    HibernateUtil.getSessionFactory().close();

}

Is there anything else I can do to prevent this error?

+3  A: 

This warning is part of memory leak protection which got shipped with Tomcat 6.0.26. In this particular issue, you seem to be using commons-pool as connection pool. It is not properly terminating the timer thread. This has already been reported as a bug: issue POOL-161. It's not fixed yet.

It does actually not harm. Tomcat is doing its job right, just live with those warnings. If they are really bothering you, you can also consider to replace the connection pool by another one. I'd recommend tomcat-jdbc.

See also:

BalusC
(+1 by the way)
Pascal Thivent