为防止内存泄漏,JDBC Driver已被强制注销 [英] To prevent a memory leak, the JDBC Driver has been forcibly unregistered

查看:53
本文介绍了为防止内存泄漏,JDBC Driver已被强制注销的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在运行 Web 应用程序时收到此消息.它运行良好,但我在关机期间收到此消息.

I am getting this message when I run my web application. It runs fine but I get this message during shutdown.

严重:Web 应用程序注册了 JBDC 驱动程序 [oracle.jdbc.driver.OracleDriver],但在 Web 应用程序停止时未能取消注册.为防止内存泄漏,JDBC Driver 已被强制注销.

SEVERE: A web application registered the JBDC driver [oracle.jdbc.driver.OracleDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.

感谢任何帮助.

推荐答案

从 6.0.24 版本开始,Tomcat 附带了 内存泄漏检测 功能,当 web 应用程序的 /WEB-INF/lib 中有兼容 JDBC 4.0 的驱动程序时,这反过来会导致此类警告消息auto-注册 在 webapp 启动期间使用 ServiceLoader API,但没有自动在 web 应用程序关闭期间取消注册.此消息纯属非正式,Tomcat已经相应采取了防止内存泄漏的措施.

Since version 6.0.24, Tomcat ships with a memory leak detection feature, which in turn can lead to this kind of warning messages when there's a JDBC 4.0 compatible driver in the webapp's /WEB-INF/lib which auto-registers itself during webapp's startup using the ServiceLoader API, but which did not auto-deregister itself during webapp's shutdown. This message is purely informal, Tomcat has already taken the memory leak prevention action accordingly.

你能做什么?

  1. 忽略这些警告.Tomcat 的工作是正确的.实际的错误在其他人的代码(有问题的 JDBC 驱动程序)中,而不是在您的代码中.很高兴 Tomcat 正确完成了它的工作,然后等待 JDBC 驱动程序供应商修复它,以便您可以升级驱动程序.另一方面,您不应该在 webapp 的 /WEB-INF/lib 中删除 JDBC 驱动程序,而只能在服务器的 /lib 中.如果你仍然把它保存在 webapp 的 /WEB-INF/lib 中,那么你应该使用 ServletContextListener 手动注册和注销它.

  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.

降级到 Tomcat 6.0.23 或更低版本,这样您就不会被这些警告所困扰.但它会默默地不断泄漏内存.不知道这毕竟是不是很好.这类内存泄漏是 OutOfMemoryError 问题背后的主要原因之一 在 Tomcat 热部署期间.

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.

将 JDBC 驱动程序移动到 Tomcat 的 /lib 文件夹,并有一个连接池数据源来管理驱动程序.请注意,Tomcat 的内置 DBCP 在关闭时不会正确注销驱动程序.另请参阅作为 WONTFIX 关闭的错误 DBCP-322.您更愿意将 DBCP 替换为另一个比 DBCP 做得更好的连接池.例如 HikariCP 或者 Tomcat JDBC 池.

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 or perhaps Tomcat JDBC Pool.

这篇关于为防止内存泄漏,JDBC Driver已被强制注销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆