Tomcat出现To prevent a memory leak, the JDBC Driver has been forcibly unregistered.问题的一种情况记录...

  • 问题出现背景:

最近重构了一个老的项目,这个项目中间曾经参与维护的人比较多,代码非常乱,所以对其进行了一次小的重构和升级,将系统环境从JDK1.6+Tomcat6+WindowsServer升级JDK1.8+Tomcat8+Linux,但是重构完成的时候出现了错误,Tomcat一直无法启动。

  • 错误信息

To prevent a memory leak, the JDBC Driver has been forcibly unregistered. 这个错误:

  • 参考的资料

参考了stack overflow上边的问题:

http://stackoverflow.com/questions/3320400/to-prevent-a-memory-leak-the-jdbc-driver-has-been-forcibly-unregistered

http://stackoverflow.com/questions/2604630/tomcat-fails-to-start-because-of-jdbc-driver-loading

从6.0.24版本开始,Tomcat加入了内存泄漏检测特性,由于原来的Tomcat版本为6.0.24版本之前的版本,没有出现类似问题,但是升级为Tomcat8之后就出现了这个问题,Tomcat启动的时候出现了一长串的重复错误信息,警告 To prevent a memory leak, the JDBC Driver has been forcibly unregistered. 

BalusC的建议:

  1. 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. On the other hand, you aren't supposed to drop a JDBC driver in webapp's?/WEB-INF/lib, but only in server's?/lib. If you still keep it in webapp's?/WEB-INF/lib, then you should manually register and deregister it using a?ServletContextListener.

  2. 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.

  3. 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?which is closed as WONTFIX. You would rather like to replace DBCP by another connection pool which is doing its job better then DBCP. For example?HikariCP,?BoneCP, or perhaps?Tomcat JDBC Pool.

按照BalusC的建议中的第三条对JDBC的Driver和连接池进行了调整,但是问题依然存在。

To prevent a memory leak, the JDBC Driver has been forcibly这个报错非常具有迷惑性,因为日志输出的错误信息中并没有提供足够的解决问题的有价值信息。

Sometimes, especially when using Spring application on Tomcat, the error message is misleading - when there is no relation to any JDBC driver error at all but only a failure of some application BEAN init-method (or @PostConstruct). The error stack trace is hidden and appears only in tomcat/logs/localhost.xxx file. Just be aware of this behavior. It costed me a lot of time.

  • 结论和解决方案

结论:Tomcat中运行Spring的项目时候,控制台输出的错误非常具有迷惑性,有时候只是一些bean初始化的时候或者@PostConstruct的时候出现错误,但是控制台却输出JDBC Driver的错误,这些错误信息对解决问题没有帮助,而真正的错误信息存在于tomcat/logs/localhost.xxx file文件中。

至此,问题的解决办法就非常清晰了,只需要去tomcat/logs/localhost.xxx 文件中找到真正的错误信息,根据真正的错误信息解决完代码中的问题后,这个问题自然也跟着就解决了。

 

转载于:https://www.cnblogs.com/mengyehongmanshan/p/6841909.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值