java.lang.IllegalStateException:当webapp在tomcat上重新部署时,计时器已经被取消

时间:2010-10-15 20:02:44

标签: java hibernate tomcat

在应用程序重新部署时在struts2 webapp中使用Hibernate,在重新部署后尝试访问页面时会出现此错误。

java.lang.IllegalStateException: Timer already cancelled.

在重新部署tomcat之后,以下输出指示问题的原因是当第一个webapp实例关闭时,Hibernate没有正常关闭。

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. 

我添加了一个ContextListener,它在contextDestroyed方法中有以下内容但是没有效果。

@Override
public void contextDestroyed(ServletContextEvent arg0) {

    HibernateUtil.getSessionFactory().close();

}

我还能做些什么来防止这个错误吗?

1 个答案:

答案 0 :(得分:6)

此警告是Tomcat 6.0.26附带的memory leak protection的一部分。在此特定问题中,似乎使用commons-pool作为连接池。它没有正确终止计时器线程。这已被报告为错误:issue POOL-161。它尚未修复。

它确实没有伤害。 Tomcat正在做正确的工作,只是接受这些警告。如果他们真的困扰你,你也可以考虑用另一个替换连接池。我建议tomcat-jdbc

另见:

相关问题