c3p0 连接池内存泄漏重新部署 tomcat
c3p0 Connection pool memory leak redeploy tomcat
我有这些用于关闭 c3p0 连接管理器的代码,但似乎还有一个线程未关闭。我错过了什么吗?
Oct 11, 2016 5:12:09 PM org.springframework.context.support.AbstractApplicationContext doClose
INFO: Closing WebApplicationContext for namespace 'dispatcherServlet-servlet': startup date [Tue Oct 11 17:11:58 PHT 2016]; parent: Root WebApplicationContext
2016-10-11 17:12:09 - [INFO ] CRMContextListener - Trying to Close
2016-10-11 17:12:09 - [INFO ] CRMContextListener - Close Success
Oct 11, 2016 5:12:09 PM org.springframework.context.support.AbstractApplicationContext doClose
INFO: Closing Root WebApplicationContext: startup date [Tue Oct 11 17:11:44 PHT 2016]; root of context hierarchy
Oct 11, 2016 5:12:09 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
SEVERE: A web application registered the JBDC driver [oracle.jdbc.OracleDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered. Oct 11, 2016 5:12:09 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: A web application appears to have started a thread named [C3P0PooledConnectionPoolManager[identityToken->2xjsis9j1do3mrp1m3tqb8|fb6fd9c]-DeferredStatementDestroyerThread-#0] but has failed to stop it. This is very likely to create a memory leak.
这是我的 servlet 侦听器的代码
public void contextDestroyed(ServletContextEvent sce) {
logger.info("Trying to Close");
for (Object o : C3P0Registry.getPooledDataSources()) {
try {
((PooledDataSource) o).close();
} catch (Exception e) {
logger.info("No thread was open...");
}
}
logger.info("Close Success");
}
这是我对 c3p0 的配置 xml
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="oracle.jdbc.driver.OracleDriver" />
<property name="jdbcUrl" value="jdbc:oracle:thin:@sph-pdc-vm 1042:1521:DEV" />
<property name="user" value="TSW" />
<property name="password" value="TSW2015#" />
<property name="minPoolSize" value="2" />
<property name="maxPoolSize" value="20" />
<property name="initialPoolSize" value="5" />
<property name="testConnectionOnCheckin" value="true" />
<property name="idleConnectionTestPeriod" value="100" />
<property name="maxIdleTimeExcessConnections" value="5" />
<property name="maxStatementsPerConnection" value="10" />
<property name="acquireIncrement" value="1" />
<property name="statementCacheNumDeferredCloseThreads" value="1" />
<property name="acquireRetryAttempts" value="2" />
<property name="acquireRetryDelay" value="2000" />
</bean>
提前致谢....
这可能不是真正的内存泄漏,而是一个错误警告,因为 c3p0 的线程需要一些时间才能结束,并且 close()
不会等待它完成,它是异步的。所以你有一个烦人的消息。请参阅 this github issue,感谢 github 上的 Buğra Gedik。如果你想测试这个理论,你可能会增加一秒左右的延迟[即。在您拨打 close()
之后拨打 Thread.sleep(1000)
] 并查看消息是否消失。
尽管我认为这不是您的问题,您也可以考虑添加一些 Tomcat 参数以确保尝试关闭 () 线程总是成功。只需添加...
<property name="privilegeSpawnedThreads" value="true" />
<property name="contextClassLoaderSource" value="library" />
我有这些用于关闭 c3p0 连接管理器的代码,但似乎还有一个线程未关闭。我错过了什么吗?
Oct 11, 2016 5:12:09 PM org.springframework.context.support.AbstractApplicationContext doClose
INFO: Closing WebApplicationContext for namespace 'dispatcherServlet-servlet': startup date [Tue Oct 11 17:11:58 PHT 2016]; parent: Root WebApplicationContext
2016-10-11 17:12:09 - [INFO ] CRMContextListener - Trying to Close
2016-10-11 17:12:09 - [INFO ] CRMContextListener - Close Success
Oct 11, 2016 5:12:09 PM org.springframework.context.support.AbstractApplicationContext doClose
INFO: Closing Root WebApplicationContext: startup date [Tue Oct 11 17:11:44 PHT 2016]; root of context hierarchy
Oct 11, 2016 5:12:09 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
SEVERE: A web application registered the JBDC driver [oracle.jdbc.OracleDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered. Oct 11, 2016 5:12:09 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: A web application appears to have started a thread named [C3P0PooledConnectionPoolManager[identityToken->2xjsis9j1do3mrp1m3tqb8|fb6fd9c]-DeferredStatementDestroyerThread-#0] but has failed to stop it. This is very likely to create a memory leak.
这是我的 servlet 侦听器的代码
public void contextDestroyed(ServletContextEvent sce) {
logger.info("Trying to Close");
for (Object o : C3P0Registry.getPooledDataSources()) {
try {
((PooledDataSource) o).close();
} catch (Exception e) {
logger.info("No thread was open...");
}
}
logger.info("Close Success");
}
这是我对 c3p0 的配置 xml
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="oracle.jdbc.driver.OracleDriver" />
<property name="jdbcUrl" value="jdbc:oracle:thin:@sph-pdc-vm 1042:1521:DEV" />
<property name="user" value="TSW" />
<property name="password" value="TSW2015#" />
<property name="minPoolSize" value="2" />
<property name="maxPoolSize" value="20" />
<property name="initialPoolSize" value="5" />
<property name="testConnectionOnCheckin" value="true" />
<property name="idleConnectionTestPeriod" value="100" />
<property name="maxIdleTimeExcessConnections" value="5" />
<property name="maxStatementsPerConnection" value="10" />
<property name="acquireIncrement" value="1" />
<property name="statementCacheNumDeferredCloseThreads" value="1" />
<property name="acquireRetryAttempts" value="2" />
<property name="acquireRetryDelay" value="2000" />
</bean>
提前致谢....
这可能不是真正的内存泄漏,而是一个错误警告,因为 c3p0 的线程需要一些时间才能结束,并且 close()
不会等待它完成,它是异步的。所以你有一个烦人的消息。请参阅 this github issue,感谢 github 上的 Buğra Gedik。如果你想测试这个理论,你可能会增加一秒左右的延迟[即。在您拨打 close()
之后拨打 Thread.sleep(1000)
] 并查看消息是否消失。
尽管我认为这不是您的问题,您也可以考虑添加一些 Tomcat 参数以确保尝试关闭 () 线程总是成功。只需添加...
<property name="privilegeSpawnedThreads" value="true" />
<property name="contextClassLoaderSource" value="library" />