tomcat启动时报to prevent a memory leak

1.tomcat6.0.28下运行一个war大概有1个月时间后的一天,客户打电话讲系统访问不了。
电话确定了不是网络问题。最后只能奔过去了。
到后发现确实是个问题:tomcat在启动时就报to prevent a memory leak错误,详细如下图,
每遇到过,百度谷歌之,发现有如下可能原因:
1)jvm内存不足
2)tomcat6.0.28版本bug,网上确实有人遇到过此问题,说5.5.29版本有修复此bug
看来真不能用太新的版本,于是换了5.5.33,发现仍然抛以上错误,
看来一半会解决不了了,安心打开个人电脑,本地测试。
乖乖的,启动服务没启动成功,抛出**用户名密码错误,
用sqlmanager检查用户名密码,发现用户密码过期,用sa登录,
看到那个用户名属性中不知怎么被设置了强制密码过期。
重新启动可以了,看来我遇到的这个memory leak应该不是tomcat版本问题。

tomcat启动时报to prevent a memory leak_第1张图片

 

 

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

最近写点代码 tomcat一直报错,但是使用都正常。
网上查了资料,大概翻译下

从版本6.0.24开始,Tomcat附带一个内存泄漏检测功能。当项目/WEB-INF/lib目录下存在jdbc 4.0的兼容驱动,项目被载入的时候该驱动会通过ServiceLoader API自动注册,但是当项目关闭的时候他不会自动注销。这样就导致该告警产生。

你可以:
1.忽略这种告警。tomcat正在正常的工作。其实是别人代码的问题(jdbc的问题),而不是你代码的问题。你应该庆幸tomcat在正常工作,等待jdbc驱动厂商把这个bug修复然后你再升级驱动。
2.使用旧版本的tomcat(低于6.0.24版本),这样告警就不会出现了。但是内存泄露依然存在。这种内存泄露是tomcat热部署时候出现OutOfMemoryError错误的主要原因。
3.将jdbc驱动移动到tomcat/lib文件夹下,并使用连接池来管理驱动。注意,tomcat内置的DBCP(连接池)并不在关闭的时候正常地注销驱动,参见BUG DBCP-322.你最好使用其他比DBCP更好的连接池来代替DBCP,比如BoneCP 或者 Tomcat JDBC Pool

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.

What can you do?
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.

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


后来在网上看到别人说,可以修改tomcat的server.xml文件,把
<!-- Prevent memory leaks due to use of particular java/javax APIs-->
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
把内存检测功能关掉。

 

Tomcat6.0.24 - Tomcat7均有如此问题。要不直接回退Tomcat到6.0.24版本以前,或者,Tomcat7


 

你可能感兴趣的:(tomcat启动时报to prevent a memory leak)