当我使用Tomcat 7 JDBC连接池取消部署Web应用程序时,为什么连接仍然存在? [英] Why do connections persist when I undeploy a webapp using the Tomcat 7 JDBC connection pool?

查看:82
本文介绍了当我使用Tomcat 7 JDBC连接池取消部署Web应用程序时,为什么连接仍然存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Tomcat 7.0.22上部署了一个最小的Spring Web应用程序-它由几个页面,一个控制器,一个服务和一个DAO组成,该DAO具有一个运行SELECT查询的方法.

I've got a minimal Spring webapp deployed to Tomcat 7.0.22 - it consists of a couple of pages, a controller, a service, and a DAO which has one method that runs a SELECT query.

该Web应用程序已配置为使用新的 Tomcat JDBC连接池-这是Web应用程序context.xml中的资源配置:

The webapp is configured to use the new Tomcat JDBC connection pool - here is the resource configuration in the webapp's context.xml:

<Resource name="jdbc/myDB"
          auth="Container"
          type="javax.sql.DataSource"
          driverClassName="oracle.jdbc.OracleDriver"
          url="jdbc:oracle:thin:@blah blah"
          factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
          maxActive="15"
          initialSize="5"
          maxWait="40000"
          validationQuery="select 1 from dual"
          removeAbandoned="true"
          removeAbandonedTimeout="300"
          logAbandoned="false"
          username="user"
          password="pass"
          testOnBorrow="true"
          validationInterval="30000"
          timeBetweenEvictionRunsMillis="60000"
          minEvictableIdleTimeMillis="60000" />

部署Web应用程序时,我看到出现5个连接(从SQL Developer查询v $ session).当我取消部署webapp时,连接仍然存在(处于等待状态).每次我重新部署Web应用程序时,都会显示5个新连接.

When I deploy the webapp I see 5 connections appear (querying v$session from SQL Developer). When I undeploy the webapp the connections persist (in state WAITING). Each time I redeploy my webapp, 5 new connections show up.

看来池仍在闲逛-Tomcat的管理器应用程序上的发现泄漏"按钮告诉我该应用程序正在泄漏内存.

It appears the pool is still hanging around - and the "Find Leaks" button on Tomcat's manager app tells me the app is leaking memory.

取消部署Web应用程序时如何摆脱池水?

How do I get rid of the pool when the webapp is undeployed?

推荐答案

(大多数情况下)该问题是自我造成的.我的数据源是在Web应用程序的web.xml中配置的,而我是通过JNDI引用它的.我现在按照Spring参考文档(

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.

如果需要使用JNDI数据源,则必须在contextDestroyed方法中关闭实现ServletContextListener的类中的数据源.

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.

这篇关于当我使用Tomcat 7 JDBC连接池取消部署Web应用程序时,为什么连接仍然存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆