首页 > 代码库 > registered the JBDC driver [oracle.jdbc.OracleDriver] but failed to unregister it when the web application was stopped. (转)

registered the JBDC driver [oracle.jdbc.OracleDriver] but failed to unregister it when the web application was stopped. (转)

最近项目中遇见一问题,在开发环境没有问题的代码,到了生产环境就会报如下错误:

 

  严重: A web application registered the JBDC driver [oracle.jdbc.OracleDriver] but failed to unregister it when the web application was stopped. 
To prevent a memory leak, the JDBC Driver has been forcibly unregistered. 
 
一开始以为是数据库账号密码错误,或数据库链接不上,因为这两个原因也确实会报这个错,可是通过确认发现不是以上两个原因引起的,当时真的是百思不得其解,后来通过一步步的排查和测试,发现,以前生产、测试、开发环境的数据库都是集群形式的,我们配的也是集群形式多个节点的数据库链接,如下:
jdbc.url=jdbc:oracle:thin:@(DESCRIPTION=(FAILOVER = yes)(ADDRESS = (PROTOCOL = TCP)(HOST =XXX.XXX.XXX.XXX)(PORT = 1521))(ADDRESS = (PROTOCOL = TCP)(HOST =XXX.XXX.XXX.XXX)(PORT = 1521))(CONNECT_DATA =http://www.mamicode.com/(SERVER = DEDICATED)(SERVICE_NAME = cedb)))
 
而我们新建的这一台生产环境连的数据库是直连的,没有做数据库集群,所以加载链接的时候报如上错误,把链接的配置设置如下即可:
jdbc.url=jdbc\:oracle\:thin\:@XXX.XXX.XXX.XXX\:1521\:cedb
 
这次的异常真的是受教了,希望可以帮到有一样困惑的朋友。
 
http://blog.csdn.net/suigaopeng/article/details/26579191
 
http://blog.sina.com.cn/s/blog_4550f3ca0101byg1.html
 
 

今天开始学习了struts2, 于是下了最新的版本struts2.2.3.1,在使用的过程中总是报错:A web application created a ThreadLocal with key of type , 尽管出现了这个错误,但是并不妨碍程序正常运行, 虽然程序虽然能正常运行,但是看的这个错误很是别扭,所以网上搜了一下看看,也就有了下面这篇文章

struts2关于A web application created a ThreadLocal with key of type 异常解决办法 

 

created a ThreadLocal with key of type [com.opensymphony.xwork2.inject.ContainerImpl$10] (value [com.opensymphony.xwork2.inject.ContainerImpl$10@12c74b9]) and a value of type [java.lang.Object[]] (value [[Ljava.lang.Object;@1a34544]) but failed to remove it。。。。

这类问题的解决办法:

       http://confluence.atlassian.com/pages/viewpage.action?pageId=218275753

看看老外的这篇,好像就是在讲这个问题,原因大概是说tomcat 6.025之后引入了一种内存泄露的检查机制,会把不能垃圾收集的对像做日志。

第一种解决办法:

使用低于6版本的tomcat

 

第二种解决办法:

在tomcat的server.xml文件(在tomcat的安装路径下的conf文件夹里)中把

<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>

这个监听给关了。

就是用<!--。。。-->把下面三句话括起来就可以啦。

<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />        <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />        <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

http://blog.csdn.net/zhuhezan/article/details/6882089

 

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:

public class XBasicDataSource extends BasicDataSource {    @Override    public synchronized void close() throws SQLException {        DriverManager.deregisterDriver(DriverManager.getDriver(url));        super.close();    }}

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.

https://issues.apache.org/jira/browse/DBCP-332

 

 

 

 

 

 
 

registered the JBDC driver [oracle.jdbc.OracleDriver] but failed to unregister it when the web application was stopped. (转)