解决 ”To prevent a memory leak, the JDBC Driver has been forcibly unregistered“

 在开发过程中,添加完UrlWriter之后,部署到了服务器环境,发生了如下错误

    

To prevent a memory leak, the JDBC Driver has been forcibly unregistered.    

   

    原来Tomcat6会起一个线程检测是否有内存泄露

写道
Ignore those warnings. Tomcat is doing its job right. The actual bug is in someone else's code (the JDBC driver in question), not in yours. Be happy that Tomcat did its job properly and wait until the JDBC driver vendor get it fixed so that you can upgrade the driver. 

Downgrade to Tomcat 6.0.23 or older so that you will not be bothered with those warnings. But it will silently keep leaking memory. Not sure if that's good to know after all. Those kind of memory leaks are one of the major causes behind OutOfMemoryError issues during Tomcat hotdeployments. 

Move the JDBC driver to Tomcat's /lib folder and have a connection pooled datasource to manage the driver. Note that Tomcat's builtin DBCP does not deregister drivers properly on close. See also bug DBCP-322. The DBCP project is however currently stalling. I wouldn't expect quick updates. You would rather like to replace DBCP by another connection pool which is doing its job better then DBCP. For example BoneCP or Tomcat JDBC Pool maybe?

 

    解决办法有两个

    1) 将UrlWirter的Filter从web.xml中去掉或者重写destory方法

    2) 将Mysql的驱动包复制一份到Tomcat的Lib目录下

posted @ 2018-04-28 15:44  n64wnc  阅读(1450)  评论(0编辑  收藏  举报