Why do connections persist when I undeploy a webapp using the Tomcat 7 JDBC connection pool?

偶尔善良 提交于 2019-12-05 06:58:02

The problem was self-inflicted (as most are). My data source was configured in my webapp's web.xml and I was referencing it via JNDI. I now create my data source as shown in the Spring reference doc (section 13.3.1) and the destroy method takes care of closing the data source and pool.

If I'd been required to stick with a JNDI data source I would have had to close out the data source in a class that implements ServletContextListener, in the contextDestroyed method.

This is a behaviour reported in Apache Tomcat bugzilla, Reference:

https://issues.apache.org/bugzilla/show_bug.cgi?id=25060

It has been corrected from Tomcat 7.0.11. Which version of Tomcat have you been using ?

If you use create the datasource as described in the Spring reference at"application level", you would a little overhead when it comes to administration tasks if you have a lot of applications and many servers.

I had the same problem and I could not use spring so I used a org.apache.tomcat.jdbc.pool.DataSourceProxy to close a Tomcat Datasource. This API provides you with functionality not yet implemented JDK DataSource interface.

DataSourceProxy myDataSource = (DataSourceProxy) myDataSource;
myDataSource.close();   
  • Also using factory="org.apache.tomcat.jdbc.pool.DataSourceFactory" and a ServletListener contextDestroyed method.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!