MySQL tomcat7 - jdbc 数据源 - 这很可能造成内存泄漏
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15632153/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
tomcat7 - jdbc datasource - This is very likely to create a memory leak
提问by arahant
I get the following messages in catalina.out log file when tomcat is shutdown. I am using Tomcat 7.x and the Tomcat JDBC data source.
当 tomcat 关闭时,我在 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.
The first one claims that the DataSource has been forcibly unregistered so that is fine. However it is strange Because I have configured the destroy-method like so:
第一个声称 DataSource 已被强行注销,所以没问题。但是很奇怪,因为我已经像这样配置了销毁方法:
<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>
Not sure why I get the second one. The one about the "MySQL Statement Cancellation Timer".
不知道为什么我得到第二个。关于“MySQL Statement Cancellation Timer”的那个。
Any help is appreciated
任何帮助表示赞赏
EDIT 1:
I tried the fix suggested by @Zelldon and it gets rid of the first error. However the MySQL Statement Cancellation Timer
related issue still persists
编辑 1:我尝试了@Zelldon 建议的修复程序,它摆脱了第一个错误。但是MySQL Statement Cancellation Timer
相关问题仍然存在
回答by Zelldon
Try to put the sql Connector/Driver in the tomcat/lib and not in the war. Because every time you deploy the war the connector/driver will be created sometimes the garbage collector cant remove them which will ends in a memory leak. So try to move the connector on the tomcat/lib folder.
尝试将 sql Connector/Driver 放在 tomcat/lib 中,而不是放在 war 中。因为每次部署War时都会创建连接器/驱动程序,有时垃圾收集器无法删除它们,这将导致内存泄漏。所以尝试将连接器移动到 tomcat/lib 文件夹中。
Please read the following answers:
请阅读以下答案:
Why must the JDBC driver be put in TOMCAT_HOME/lib folder?
为什么JDBC驱动必须放在TOMCAT_HOME/lib文件夹中?
回答by Atropo
It could be related to this bug in the MySQL jdbc connector: http://bugs.mysql.com/bug.php?id=65909.
它可能与 MySQL jdbc 连接器中的这个错误有关:http: //bugs.mysql.com/bug.php? id= 65909。
You can wait for the MySQL team to fix it, or you try to use the Drizzle JDBC connectorwhich works fine with MySQL (you have just to change the parameter in the url connection) and, in my tests, doesn't have this kind of bug.
您可以等待 MySQL 团队修复它,或者您尝试使用适用于 MySQL的Drizzle JDBC 连接器(您只需更改 url 连接中的参数),并且在我的测试中没有这种的错误。
回答by Cheng Jiang
I met the same problem just like you ,and I just roll back the pom version of mysql-connector-java from 8.0.16 to 8.0.15 and the problem got resolved,I think it's the unmatch between the version of connector and mysql that caused the problem
我和你一样遇到了同样的问题,我只是将mysql-connector-java的pom版本从8.0.16回滚到8.0.15,问题解决了,我认为是connector版本和mysql版本不匹配造成的导致问题