困扰老子好久啊!!tomcat的两个错…

本文介绍了在Tomcat6中遇到的两个常见内存泄漏问题及其解决方案。第一个问题是由于重复加载了MySQL JDBC驱动而导致的内存泄漏警告;第二个问题是由于线程局部变量未能正确清理引发的警告。文章提供了详细的解决步骤,包括调整配置文件和合理放置驱动包。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天tomcat 6遇到两个错误提示:
1.
严重: 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.


原因:重复加载了jar包。
解决方法:原来我在tomcat的lib文件夹放入了com.mysql.jdbc.Driver的jar包,而又在项目里面重复添加了,导致了上面的提示。删掉其中一个解决问题。


2.The web application [/snoopy] created a ThreadLocal with key of type [com.opensymphony.xwork2.inject.ContainerImpl$10] (value [com.opensymphony.xwork2.inject.ContainerImpl$10@ea85b4]) and a value of type [java.lang.Object[]] (value [[Ljava.lang.Object;@efeff8]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.


原因:tomcat 6.026之后的版本加入了 memory leak detection feature(内存泄露检查)看如下原文:
There is a memory leak detection feature introduced in Tomcat 6.0.26 that attempts to log objects that have failed to be unregistered by webapps it hosts when they are stopped, and were forcibly unregistered by Tomcat. As Tomcat is forcibly removing these objects, it is not a serious concern that these log messages occur.


解决方法:在tomcat 的server.xml文件中将注释掉即可
PS:这是一个治标不治本的方法。
 
***********************************

     

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

    

Java代码 复制代码  收藏代码困扰老子好久啊!!tomcat的两个错误提示
  1. To prevent memory leak, the JDBC Driver has been forcibly unregistered.    
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目录下

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

huangleijay

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值