[英]Why do connections persist when I undeploy a webapp using the Tomcat 7 JDBC connection pool?
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. 我有一个部署到Tomcat 7.0.22的最小Spring Web应用程序 - 它包含几个页面,一个控制器,一个服务和一个DAO,它有一个运行SELECT查询的方法。
The webapp is configured to use the new Tomcat JDBC connection pool - here is the resource configuration in the webapp's context.xml: webapp配置为使用新的Tomcat JDBC连接池 - 这是webapp的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" />
When I deploy the webapp I see 5 connections appear (querying v$session from SQL Developer). 当我部署webapp时,我看到出现了5个连接(从SQL Developer查询v $ session)。 When I undeploy the webapp the connections persist (in state WAITING).
当我取消部署webapp时,连接仍然存在(状态为WAITING)。 Each time I redeploy my webapp, 5 new connections show up.
每次重新部署我的webapp时,都会显示5个新连接。
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. 看来游泳池仍在闲逛 - 而Tomcat经理应用程序中的“Find Leaks”按钮告诉我应用程序正在泄漏内存。
How do I get rid of the pool when the webapp is undeployed? 取消部署webapp时如何摆脱池?
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.
我的数据源是在我的webapp的web.xml中配置的,我通过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. 我现在创建我的数据源,如Spring参考文档( 第13.3.1节 )中所示,
destroy
方法负责关闭数据源和池。
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. 如果我被要求坚持使用JNDI数据源,我将不得不在
contextDestroyed
方法中关闭实现ServletContextListener
的类中的数据源。
This is a behaviour reported in Apache Tomcat bugzilla, Reference: 这是Apache Tomcat bugzilla中报告的行为,参考:
https://issues.apache.org/bugzilla/show_bug.cgi?id=25060 https://issues.apache.org/bugzilla/show_bug.cgi?id=25060
It has been corrected from Tomcat 7.0.11. 它已从Tomcat 7.0.11更正。 Which version of Tomcat have you been using ?
您使用的是哪个版本的Tomcat?
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. 如果您使用如“应用程序级别”的Spring参考中所述创建数据源,那么如果您有许多应用程序和许多服务器,那么在管理任务时您会有一点开销。
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. 我有同样的问题,我无法使用spring,所以我使用org.apache.tomcat.jdbc.pool.DataSourceProxy来关闭Tomcat数据源。 This API provides you with functionality not yet implemented JDK DataSource interface.
此API为您提供尚未实现的JDK DataSource接口功能。
DataSourceProxy myDataSource = (DataSourceProxy) myDataSource;
myDataSource.close();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.