tomcat7 - jdbc 数据源 - 这很可能造成内存泄漏

tomcat7 - jdbc datasource - This is very likely to create a memory leak(tomcat7 - jdbc 数据源 - 这很可能造成内存泄漏)
本文介绍了tomcat7 - jdbc 数据源 - 这很可能造成内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当 tomcat 关闭时,我在 catalina.out 日志文件中收到以下消息.我使用的是 Tomcat 7.x 和 Tomcat JDBC 数据源.

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.

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 已被强行注销,所以没问题.但是很奇怪,因为我已经像这样配置了销毁方法:

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:

<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 Statement Cancellation Timer"的那个.

Not sure why I get the second one. The one about the "MySQL Statement Cancellation Timer".

感谢任何帮助

编辑 1:我尝试了@Zelldon 建议的修复程序,它消除了第一个错误.但是MySQL Statement Cancellation Timer相关问题依然存在

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

推荐答案

尽量把 sql Connector/Driver 放在 tomcat/lib 里,不要放在 war 里.因为每次部署战争时都会创建连接器/驱动程序,有时垃圾收集器无法删除它们,这将导致内存泄漏.所以尽量把连接器移到tomcat/lib文件夹中.

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.

请阅读以下答案:

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

如何配置Tomcat连接MySQL

这篇关于tomcat7 - jdbc 数据源 - 这很可能造成内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)
SQL/MySQL: split a quantity value into multiple rows by date(SQL/MySQL:按日期将数量值拆分为多行)