The web application [] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lihongjian944043440/article/details/6874760

声明:本文转自mtgongren的博客,如有需要,请联系本作者。谢谢!

暑假的时候做了一个项目,用的是SSH+MySQL5.0+tomcat5.5

做完部署到服务器后(tomcat是6.0.32),测试正常运行。第二天发现无法登录了,检查了一遍系统没发现什么问题,重启tomcat后又恢复正常了。
很奇怪,于是查看tomcat的日志,发现如下问题:

2011-9-1 0:15:11 org.apache.catalina.startup.Catalina start
信息: Server startup in 35866 ms
2011-9-1 2:05:43 org.apache.coyote.http11.Http11Protocol pause
信息: Pausing Coyote HTTP/1.1 on http-8080
2011-9-1 2:05:44 org.apache.catalina.core.StandardService stop
信息: Stopping service Catalina
2011-9-1 2:05:44 org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
严重: The web application [] 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.
2011-9-1 2:05:45 org.apache.coyote.http11.Http11Protocol destroy
信息: Stopping Coyote HTTP/1.1 on http-8080

看报的异常信息是应用程序注册了JDBC驱动,但当程序停止时无法注销这个驱动,tomcat为了防止内存溢出,就给强制注销了。
上网搜,发现网上有不少关于这个问题的讨论,说是DBCP的bug。

详细如下:
https://issues.apache.org/jira/browse/DBCP-332 

Description

BasicDataSource's method close() doesn't deregister JDBC driver. This causes permgen memory leaks in web server environments, during context reloads. For example, using Tomcat 6.0.26 with Spring, and BasicDataSource declared in Spring context, there is a message printed at web application reload:

SEVERE: A web application registered the JBDC 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.

I was able to fix it by overriding close method this way:

  1. public class XBasicDataSource extends BasicDataSource {  
  2.     @Override  
  3.     public synchronized void close() throws SQLException {  
  4.         DriverManager.deregisterDriver(DriverManager.getDriver(url));  
  5.         super.close();  
  6.     }  
  7. }  

but I think it should be probably the default behavior of BasicDataSource. Or perhaps there should be some flag/setting on BasicDataSource, named "deregisterDriverAtClose" or so.

我的系统没有用spring配置数据源。

tomcat从6.0.24版本之后引入了内存泄漏侦测的功能,当发现系统有垃圾无法回收时,就会输出日志信息。



看了很多关于这个问题的讨论,好像也没发现什么好的解决方法。有的说把tomcat的内存监听器关了就不会报这个异常,可是不报不等于没问题,依然无法解决啊。感觉应该是Hibernate的默认连接池对数据库连接的管理存在bug,其不会对连接是否有效进行检查,所以会出现异常。
在网上搜了关于Hibernate配置MySQL的资料,发现Mysql有个8小时问题,即系统如果超过8个小时没有被访问,mysql就会关闭空闲的Connection连接,而hibernate不会对连接是否有效进行检查,导致系统无法连接数据库。
在看了很多资料后,基本上可以确定是数据库连接的管理出了问题,用的是Hibernate3,配置数据库的时候用的是Hibernate默认的连接池,尝试更换成了Proxool连接池。
参考如下:
http://www.360doc.com/content/08/0101/10/53523_938529.shtml

3. proxool连接池

       proxool跟c3p0以及dbcp不一样,它是自己生成连接的,因此连接信息放在proxool配置文件中。使用它时,需要将proxool-0.8.3.jar加入到classespath中。配置举例如下:

hibernate.cfg.xml

  1. <?xml version="1.0" encoding="UTF-8"?>  
  2.   
  3. <!DOCTYPE hibernate-configuration PUBLIC  
  4.   
  5. "-//Hibernate/Hibernate Configuration DTD 3.0//EN"  
  6.   
  7. "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">  
  8.   
  9. <hibernate-configuration>  
  10.   
  11. <session-factory>  
  12.   
  13.         <!-- 显示实际操作数据库时的SQL -->  
  14.   
  15.         <property name="show_sql">true</property>  
  16.   
  17.         <!-- SQL方言,这边设定的是MySQL -->  
  18.   
  19.         <property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>  
  20.   
  21. <!—proxool的配置 -->  
  22.   
  23.        <property name="proxool.pool_alias">pool1</property>  
  24.   
  25. <property name="proxool.xml">ProxoolConf.xml</property>  
  26.   
  27. <property name="connection.provider_class">net.sf.hibernate.connection.ProxoolConnectionProvider</property>  
  28.   
  29.        <!-- 对象与数据库表格映像文件 -->  
  30.   
  31.        <mapping resource="com/amigo/pojo/User.hbm.xml"/>  
  32.   
  33. <mapping resource="com/amigo/pojo/Org.hbm.xml"/>  
  34.   
  35.   </session-factory>  
  36.   
  37. </hibernate-configuration>  


在hibernate.cfg.xml的同目录下编写proxool的配置文件:ProxoolConf.xml,该文件的配置实例如下:

ProxoolConf.xml

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <!-- the proxool configuration can be embedded within your own application's.  
  3. Anything outside the "proxool" tag is ignored. -->  
  4. <something-else-entirely>  
  5. <proxool>  
  6. <alias>pool1</alias>  
  7. <!--proxool只能管理由自己产生的连接-->  
  8.   
  9. <!-- 驱动的url-->  
  10.   
  11. <!-- jdbc:mysql://localhost:3306/dbname?useUnicode=true&characterEncoding=GBK-->  
  12.   
  13. <driver-url>… </driver-url>  
  14.   
  15. <!-- 驱动类,eg. com.mysql.jdbc.Driver-->  
  16.   
  17. <driver-class>… </driver-class>  
  18. <driver-properties>  
  19.   
  20. <!-- 数据库用户名,eg. value为root-->  
  21.   
  22. <property name="user" value="…"/>  
  23.   
  24. <!-- 数据库密码,eg. value为root-->  
  25.   
  26. <property name="password" value="…."/>  
  27. </driver-properties>  
  28. <!-- proxool自动侦察各个连接状态的时间间隔(毫秒),侦察到空闲的连接就马上回收,超时的销毁-->  
  29. <house-keeping-sleep-time>90000</house-keeping-sleep-time>  
  30. <!-- 指因未有空闲连接可以分配而在队列中等候的最大请求数,超过这个请求数的用户连接就不会被接受-->  
  31. <maximum-new-connections>20</maximum-new-connections>  
  32. <!-- 最少保持的空闲连接数-->  
  33. <prototype-count>5</prototype-count>  
  34. <!-- 允许最大连接数,超过了这个连接,再有请求时,就排在队列中等候,最大的等待请求数由maximum-new-connections决定-->  
  35. <maximum-connection-count>100</maximum-connection-count>  
  36. <!-- 最小连接数-->  
  37. <minimum-connection-count>10</minimum-connection-count>  
  38. </proxool>  
  39. </something-else-entirely>  



按照上面讲的加入了Proxool0.9.1的jar包并配置好了,测试时却不通过,报没有jdbc connection的异常,奇怪。一个哥们和我一起按照上面的配置,他的却通过了,看了他的配置文件发现他的hibernate.cfg.xml里依然配置有数据库的连接信息,这个应该不需要了,因为在Proxool.xml里配置了啊。难道是因为这个,我也加上连接信息进行测试,结果正常登录,把系统日期往后调了几天再进行登录测试,又报了一开始的那个异常。很明显我配的这个连接池没有起作用,很奇怪。我哥们把他的Hibernate.cfg.xml里的数据库连接配置去掉后,他的依然可以运行通过,而且系统调时间后也可以运行,说明这个连接池起作用了,问题终于算是解决了,很高兴。可是我们的代码是一样的,对比了各自的配置文件也都是一样的啊,为什么在我这不起作用呢?很是郁闷,难道是人品的问题?!不会的,我人品应该还可以啊,可是残酷的现实就摆在眼前。。。。。。不管了,都中午一点多了,午饭还没吃呢,去吃饭。
在学校外面的兰州拉面馆吃了碗牛肉刀削面,回来后还是想着这个问题,搁心里憋的慌。想了一会,觉得应该还是Hibernate.cfg.xml和proxool.xml配置文件的问题,于是我把哥们的这两个配置文件拷贝到我的系统里,把我的替换掉。运行通过。。。。。。晕死,配置文件的内容是我直接拷贝网页上的,可能存在一些字符问题。这样测试还是不放心,又把系统放到了一个小服务器上跑段时间看还会不会出现问题。
结果跑了几天后,依然正常。
阅读更多
换一批

请教registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister

01-04

部署JSP时出现:rn[/openmeetings] startup failed due to previous errorsrn2013-01-04 22:51:25,676 [main] ERROR o.a.c.loader.WebappClassLoader - The web application [/openmeetings] 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.rn2013-01-04 22:51:25,676 [main] ERROR o.a.c.loader.WebappClassLoader - The web application [/openmeetings] registered the JDBC driver [org.apache.derby.jdbc.AutoloadedDriver40] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.rn2013-01-04 22:51:25,676 [main] ERROR o.a.c.loader.WebappClassLoader - The web application [/openmeetings] registered the JDBC driver [org.apache.derby.jdbc.ClientDriver40] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.rn2013-01-04 22:51:25,676 [main] ERROR o.a.c.loader.WebappClassLoader - The web application [/openmeetings] registered the JDBC driver [org.postgresql.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.rn请教高手,这是什么问题?我已经把mysql-connector-java-5.1.22-bin.jar包导入到openmeetings\webapps\openmeetings\WEB-INF\lib目录下了。怎么解决?谢谢!!

The web application [] registered the JDBC driver [com.mysql.jdbc.Driver] but fa

05-03

现在用SSH框架开发一个博客项目。开发环境[code=text]win7 64bit myEclipse 10.x tomcat7.x jdbc:mysql-connector-java-5.1.25 struts2.0.x Hibernate3 Spring2.0.8 MySQL5.5[/code]。rn问题是这样的,每当我重新部署项目的时候,就会报这的提示信息:[code=text]五月 03, 2014 6:18:49 上午 org.apache.catalina.loader.WebappClassLoader clearReferencesJdbcrn严重: The web application [/personalblog] 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.rn五月 03, 2014 6:18:49 上午 org.apache.catalina.loader.WebappClassLoader clearReferencesThreadsrn严重: The web application [/personalblog] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak.rn五月 03, 2014 6:18:49 上午 org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaksrn严重: The web application [/personalblog] created a ThreadLocal with key of type [com.opensymphony.xwork2.inject.ContainerImpl$10] (value [com.opensymphony.xwork2.inject.ContainerImpl$10@62604ef8]) and a value of type [com.opensymphony.xwork2.inject.InternalContext[]] (value [[Lcom.opensymphony.xwork2.inject.InternalContext;@20e0ae3d]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.[/code]。rn说是注册JDBC驱动,但是当Web应用程序关闭时无法注销.为了避免内存泄露,JDBC驱动被强制注销了。rn我Google了一下,好多人都遇到了这种情况,但是也没找到特别好的解决方案。故,特此来这里请求大家的帮助。先谢谢大家了。

求助!The web application [/Root] registered the JDBC driver [com.mysql.jdbc.Driver

07-26

目录结构:D:\xmgk\companyweb\www.test.com\test\Root\工程内容rn D:\xmgk\companyweb\www.test.com\testMobile\Root\工程内容rnhosts文件添加rnrn 127.168.0.0.1 mobile.test.comrntomcat/conf/server:rnrnrn rn rnrnrn rn 严重: The web application [/Root] 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.rn七月 26, 2016 10:19:37 上午 org.apache.catalina.loader.WebappClassLoader clearReferencesThreadsrn严重: The web application [/Root] appears to have started a thread named [Timer-0] but has failed to stop it. This is very likely to create a memory leak.rn七月 26, 2016 10:19:37 上午 org.apache.catalina.loader.WebappClassLoader clearReferencesThreadsrn严重: The web application [/Root] appears to have started a thread named [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0] but has failed to stop it. This is very likely to create a memory leak.rn七月 26, 2016 10:19:37 上午 org.apache.catalina.loader.WebappClassLoader clearReferencesThreadsrn严重: The web application [/Root] appears to have started a thread named [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1] but has failed to stop it. This is very likely to create a memory leak.rn七月 26, 2016 10:19:37 上午 org.apache.catalina.loader.WebappClassLoader clearReferencesThreadsrn严重: The web application [/Root] appears to have started a thread named [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2] but has failed to stop it. This is very likely to create a memory leak.rn七月 26, 2016 10:19:37 上午 org.apache.catalina.loader.WebappClassLoader clearReferencesThreadsrn严重: The web application [/Root] 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.rn七月 26, 2016 10:19:37 上午 org.apache.catalina.loader.WebappClassLoader clearReferencesThreadsrn严重: The web application [/Root] appears to have started a thread named [scheduler_Worker-1] but has failed to stop it. This is very likely to create a memory leak.rn七月 26, 2016 10:19:37 上午 org.apache.catalina.loader.WebappClassLoader clearReferencesThreadsrn严重: The web application [/Root] appears to have started a thread named [scheduler_Worker-2] but has failed to stop it. This is very likely to create a memory leak.rn七月 26, 2016 10:19:37 上午 org.apache.catalina.loader.WebappClassLoader clearReferencesThreadsrn严重: The web application [/Root] appears to have started a thread named [scheduler_Worker-3] but has failed to stop it. This is very likely to create a memory leak.rn七月 26, 2016 10:19:37 上午 org.apache.catalina.loader.WebappClassLoader clearReferencesThreadsrn严重: The web application [/Root] appears to have started a thread named [scheduler_Worker-4] but has failed to stop it. This is very likely to create a memory leak.rn七月 26, 2016 10:19:37 上午 org.apache.catalina.loader.WebappClassLoader clearReferencesThreadsrn严重: The web application [/Root] appears to have started a thread named [scheduler_Worker-5] but has failed to stop it. This is very likely to create a memory leak.rn七月 26, 2016 10:19:37 上午 org.apache.catalina.loader.WebappClassLoader clearReferencesThreadsrn严重: The web application [/Root] appears to have started a thread named [scheduler_Worker-6] but has failed to stop it. This is very likely to create a memory leak.rn七月 26, 2016 10:19:37 上午 org.apache.catalina.loader.WebappClassLoader clearReferencesThreadsrn严重: The web application [/Root] appears to have started a thread named [scheduler_Worker-7] but has failed to stop it. This is very likely to create a memory leak.rn七月 26, 2016 10:19:37 上午 org.apache.catalina.loader.WebappClassLoader clearReferencesThreadsrn严重: The web application [/Root] appears to have started a thread named [scheduler_Worker-8] but has failed to stop it. This is very likely to create a memory leak.rn七月 26, 2016 10:19:37 上午 org.apache.catalina.loader.WebappClassLoader clearReferencesThreadsrn严重: The web application [/Root] appears to have started a thread named [scheduler_Worker-9] but has failed to stop it. This is very likely to create a memory leak.rn七月 26, 2016 10:19:37 上午 org.apache.catalina.loader.WebappClassLoader clearReferencesThreadsrn严重: The web application [/Root] appears to have started a thread named [scheduler_Worker-10] but has failed to stop it. This is very likely to create a memory leak.rn七月 26, 2016 10:19:37 上午 org.apache.coyote.AbstractProtocol stop

没有更多推荐了,返回首页