`
mmdev
  • 浏览: 12914588 次
  • 性别: Icon_minigender_1
  • 来自: 大连
文章分类
社区版块
存档分类
最新评论

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

 
阅读更多

声明:本文转自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. publicclassXBasicDataSourceextendsBasicDataSource{
  2. @Override
  3. publicsynchronizedvoidclose()throwsSQLException{
  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. <?xmlversion="1.0"encoding="UTF-8"?>
  2. <!DOCTYPEhibernate-configurationPUBLIC
  3. "-//Hibernate/HibernateConfigurationDTD3.0//EN"
  4. "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
  5. <hibernate-configuration>
  6. <session-factory>
  7. <!--显示实际操作数据库时的SQL-->
  8. <propertyname="show_sql">true</property>
  9. <!--SQL方言,这边设定的是MySQL-->
  10. <propertyname="dialect">net.sf.hibernate.dialect.MySQLDialect</property>
  11. <!—proxool的配置-->
  12. <propertyname="proxool.pool_alias">pool1</property>
  13. <propertyname="proxool.xml">ProxoolConf.xml</property>
  14. <propertyname="connection.provider_class">net.sf.hibernate.connection.ProxoolConnectionProvider</property>
  15. <!--对象与数据库表格映像文件-->
  16. <mappingresource="com/amigo/pojo/User.hbm.xml"/>
  17. <mappingresource="com/amigo/pojo/Org.hbm.xml"/>
  18. </session-factory>
  19. </hibernate-configuration>


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

ProxoolConf.xml

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



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

相关推荐

    Proxool-0.9.1

    SEVERE: The web application [/xxx] 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 ...

    关闭tomca报错t,网络整理

    严重: The web application [/img] 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...

    Tomcat报错: JDBC unregister 解决办法

    主要介绍了Tomcat报错: JDBC unregister 解决办法的相关资料,需要的朋友可以参考下

    Senfore_DragDrop_v4.1

    I have not been able to reproduce these errors, but I believe the following work around will fix the problem: In the project options of *all* projects which uses these components, add the following...

    DriverStudio 3.2 For VisualStudio 2005 补丁

    &lt;br&gt;原文件说明: &lt;br&gt;Compuware DriverStudio – DriverSuite Version 3.2 &lt;br&gt;Version 3.2 VisualStudio 2005 Integration fix. The purpose of this update is to allow DriverStudio – ...

    Unregister-MissingMSIs.ps1

    Windows Installer注册表修复工具 作者源址:https://gist.github.com/heaths/77fbe0b44496960fab25c2eb0b9e8475

    dx修复工具

    The Online Edition is similar to the Standard Edition, but the files for repairing are not included in Online Edition. Consequently, Internet connection is required when it is repairing the files. ...

    plsqldev14.0.0.1961x64多语言版+sn.rar

    The new viewer allows you to ignore differences in case and white space as usual, but it can also ignore differences in comments. Program Window enhancements The Program Window now highlights ...

    com.zend.php.core_9.0.0.201111081531.jar

    第一步:如果已经安装过Zend Studio 9.0的,请打开Zend Studio 9.0,在菜单中“help&gt;Unregister”,如果显示是灰的跳过此步退出Zend Studio。如果显示可以点击的请点击,这时Zend Studio会重启,重启到要求你填注册码...

    plsqldev14.0.0.1961x32多语言版+sn.rar

    The new viewer allows you to ignore differences in case and white space as usual, but it can also ignore differences in comments. Program Window enhancements The Program Window now highlights ...

    VB编程资源大全(英文控件)

    &lt;END&gt;&lt;br&gt;30,AnimatedAgent.zip Two VBScripts which allow the users to INSTANTLY create MS Agent EMAIL and MS AGENT Web pages or add MS Agent to web pages&lt;END&gt;&lt;br&gt;31,label3d.zip This ActiveX ...

    ActiveX Manager

    How many times have you tried to register/unregister an ActiveX control (OCX) and wished there was a better way to do it then REGSVR32? ActiveX Manager enables users and developers to manage ...

    OSGI in Action

    Introducing lifecycle to the paint program 73 ■ The OSGi framework’s role in the lifecycle 75 ■ The bundle activator manifest entry 76 ■ Introducing the lifecycle API 77 ■ Lifecycle state diagram...

    evid4226patch223d-en.zip_EvID4226Patch22_EvID4226Patch223d_EvID4

    Please place this entire folder (complete with contents) into your System32 directory folder ...Double click on the UnRegister .bat file to UnRegister It s as simple as that! Cheers

    gertt点阵图读取器(opengl)

    MessageBox(NULL,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; // Return FALSE } if (fullscreen) // Attempt Fullscreen Mode? { ...

    opengl画图程序附带源代码

    MessageBox(NULL,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; // Return FALSE } if (fullscreen) // Attempt Fullscreen Mode? { DEVMODE dmScreenSettings; //...

    softap_ap6212a0_tinav2.1_验证通过_旧版本的系统_20170915_1223没有外层目录.7z

    旧版本版本的全志R16平台的tinav2.1的系统打开softAP 2017/9/14 17:25 版本:V1.0 1、原始编译: ...rootroot@cm-System-Product-Name:~$ cd /home/wwt/ ...rootroot@cm-System-Product-Name:/home/wwt$ tar zxvf...

    Android代码-如何自己实现一个 EventBus

    EventBus.unRegister(this) 实现事件 Event 实体类(实现 IEvent 接口) class XXXXEvent: IEvent 发送事件 EventBus.post(XXXEvent()) 利用注解实现事件订阅执行方法 tag 用于细化区分事件 mode 方法执行线程 @...

    libdump_sr.zip

    Run ..\LibDump\LibDump.EXE using the command line option -Unregister b. Delete ..\LibDump. -------------------------- 4. COMMENTS AND BUG REPORT -------------------------- If you have any comments,...

    通信模块封装同步ModuleBus.zip

    For example on Android, activities and fragments should usually register according to their life cycle:@Override public void onStart() {  super.onStart();  ModuleBus.getInstance().register(this)...

Global site tag (gtag.js) - Google Analytics