tomcat7 – jdbc datasource – 这很可能造成内存泄漏

当tomcatclosures时,我在catalina.out日志文件中得到以下消息。 我正在使用Tomcat 7.x和Tomcat JDBC数据源。

Mar 26, 2013 1:17:52 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc SEVERE: The web application [/my_webapp] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered. Mar 26, 2013 1:17:52 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads SEVERE: The web application [/my_webapp] appears to have started a thread named [MySQL Statement Cancellation Timer] but has failed to stop it. This is very likely to create a memory leak. 

第一个声称DataSource已被强制注销,所以没有问题。 然而,这很奇怪,因为我已经configuration了这样的销毁方法:

 <bean name="dataSource" class="org.apache.tomcat.jdbc.pool.DataSource" destroy-method="close"> <property name="driverClassName" value="com.mysql.jdbc.Driver"/> <property name="url" value="jdbc:mysql://localhost:3306/mydb"/> <property name="username" value="root"/> <property name="password" value="password"/> </bean> 

不知道为什么我得到第二个。 关于“MySQL语句取消计时器”的一个。

任何帮助表示赞赏

编辑1:我尝试了@Zelldonbuild议的修复,它摆脱了第一个错误。 但是MySQL Statement Cancellation Timer相关的问题仍然存在

尝试将SQL连接器/驱动程序放在tomcat / lib中,而不是在战争中。 因为每次部署战争连接器/驱动程序将创build有时垃圾收集器不能删除它们将以内存泄漏结束。 所以尝试移动tomcat / lib文件夹上的连接器。

请阅读以下答案:

为什么JDBC驱动程序必须放在TOMCAT_HOME / lib文件夹中?

如何configurationTomcat与MySQL连接

它可能与MySQL jdbc连接器中的这个错误有关: http : //bugs.mysql.com/bug.php ?id= 65909 。

您可以等待MySQL团队修复它,或者您尝试使用与MySQL一起正常工作的Drizzle JDBC连接器 (您只需要更改url连接中的参数),并且在我的testing中,没有这种types的bug。

Interesting Posts