Tomcat内存泄漏很厉害,一般这个如何测试知道哪里除了问题

大_爱 2012-08-03 03:53:40
在关闭Tomcat的时候报了很多错,贴上错误代码

SEVERE: The web application [] registered the JDBC 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.
Jan 03, 2002 7:09:16 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak.
Jan 03, 2002 7:09:16 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named [Thread-9] but has failed to stop it. This is very likely to create a memory leak.
Jan 03, 2002 7:09:16 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named [Thread1] but has failed to stop it. This is very likely to create a memory leak.
Jan 03, 2002 7:09:16 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named [pool-1-thread-7] but has failed to stop it. This is very likely to create a memory leak.
Jan 03, 2002 7:09:16 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named [pool-1-thread-8] but has failed to stop it. This is very likely to create a memory leak.
Jan 03, 2002 7:09:16 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named [pool-1-thread-9] but has failed to stop it. This is very likely to create a memory leak.
Jan 03, 2002 7:09:16 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named [pool-1-thread-10] but has failed to stop it. This is very likely to create a memory leak.
Jan 03, 2002 7:09:16 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named [pool-1-thread-11] but has failed to stop it. This is very likely to create a memory leak.
Jan 03, 2002 7:09:16 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named [pool-1-thread-12] but has failed to stop it. This is very likely to create a memory leak.
Jan 03, 2002 7:09:16 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named [pool-1-thread-13] but has failed to stop it. This is very likely to create a memory leak.
Jan 03, 2002 7:09:16 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named [pool-1-thread-14] but has failed to stop it. This is very likely to create a memory leak.
Jan 03, 2002 7:09:16 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named [pool-1-thread-15] but has failed to stop it. This is very likely to create a memory leak.
Jan 03, 2002 7:09:16 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named [pool-1-thread-16] but has failed to stop it. This is very likely to create a memory leak.
Jan 03, 2002 7:09:16 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named [pool-1-thread-17] but has failed to stop it. This is very likely to create a memory leak.
Jan 03, 2002 7:09:16 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named [pool-1-thread-21] but has failed to stop it. This is very likely to create a memory leak.
Jan 03, 2002 7:09:16 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named [pool-1-thread-22] but has failed to stop it. This is very likely to create a memory leak.
Jan 03, 2002 7:09:16 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named [pool-1-thread-23] but has failed to stop it. This is very likely to create a memory leak.
Jan 03, 2002 7:09:16 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named [pool-1-thread-24] but has failed to stop it. This is very likely to create a memory leak.
Jan 03, 2002 7:09:16 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named [pool-1-thread-25] but has failed to stop it. This is very likely to create a memory leak.
Jan 03, 2002 7:09:16 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named [pool-1-thread-26] but has failed to stop it. This is very likely to create a memory leak.
Jan 03, 2002 7:09:16 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named [pool-1-thread-27] but has failed to stop it. This is very likely to create a memory leak.
Jan 03, 2002 7:09:16 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named [pool-1-thread-28] but has failed to stop it. This is very likely to create a memory leak.
Jan 03, 2002 7:09:16 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named [pool-1-thread-29] but has failed to stop it. This is very likely to create a memory leak.
Jan 03, 2002 7:09:16 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named [pool-1-thread-30] but has failed to stop it. This is very likely to create a memory leak.
Jan 03, 2002 7:09:16 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named [pool-1-thread-31] but has failed to stop it. This is very likely to create a memory leak.
Jan 03, 2002 7:09:16 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named [pool-1-thread-32] but has failed to stop it. This is very likely to create a memory leak.
Jan 03, 2002 7:09:16 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named [pool-1-thread-33] but has failed to stop it. This is very likely to create a memory leak.
Jan 03, 2002 7:09:16 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named [pool-1-thread-34] but has failed to stop it. This is very likely to create a memory leak.
Jan 03, 2002 7:09:16 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named [pool-1-thread-35] but has failed to stop it. This is very likely to create a memory leak.
Jan 03, 2002 7:09:16 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named [pool-1-thread-36] but has failed to stop it. This is very likely to create a memory leak.
Jan 03, 2002 7:09:16 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named [pool-1-thread-37] but has failed to stop it. This is very likely to create a memory leak.
Jan 03, 2002 7:09:16 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named [pool-1-thread-38] but has failed to stop it. This is very likely to create a memory leak.
Jan 03, 2002 7:09:16 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named [Timer-3] but has failed to stop it. This is very likely to create a memory leak.
Jan 03, 2002 7:09:16 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named [pool-1-thread-49] but has failed to stop it. This is very likely to create a memory leak.
Jan 03, 2002 7:09:16 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named [pool-1-thread-50] but has failed to stop it. This is very likely to create a memory leak.
Jan 03, 2002 7:09:16 AM org.apache.coyote.http11.Http11Protocol destroy
INFO: Stopping Coyote HTTP/1.1 on http-80

希望大家能讨论讨论这个一般是由什么问题引起的,如何解决,或者有没有比较好的工具可以测试



一下是CSDN广告,与本人无关
...全文
30605 29 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
29 条回复
切换为时间正序
请发表友善的回复…
发表回复
大_爱 2012-08-04
  • 打赏
  • 举报
回复
多谢大家,我现在正在处理,一会结贴。
大_爱 2012-08-04
  • 打赏
  • 举报
回复
[Quote=引用 19 楼 的回复:]

引用 14 楼 的回复:
关闭tomcat后,执行ps -ef | grep tomcat 还有很多进程

你的tomcat都没关掉吧,都是启动tomcat的进程,能启动多个吗?端口什么的都冲突了,LZ试试看kill掉再重启
[/Quote]

我用的shutdown.sh关闭tomcat的,关闭tomcat的时候会等很久才能关闭,关闭后用这个命名看还有很多线程
oodick 2012-08-04
  • 打赏
  • 举报
回复
是不是需要修改下tomcat的内存?
ArayChou 2012-08-04
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 的回复:]

关闭tomcat后,执行ps -ef | grep tomcat 还有很多进程
[/Quote]
还有很多进程的原因是因为Tomcat中嗨哟很多线程,就是主贴中的那些报错信息中的那些线程.

上策是,按照7楼说的做,这些对象都关闭了tomcat自然会推出

中策是,不要在tomcat中reload应用,每次都重启tomcat.在执行shutdown.sh后,看到catalina.out中没有日志输出后,直接把tomcat的进程kill掉.
ArayChou 2012-08-04
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 的回复:]
Tomcat7是吧? 它增加了一个内存泄漏的检查,主要是判断web应用重载时,类加载器中所有对象的引用都释放干净。

一般出现提示可能的原因:
1.JDBC驱动注册
2.一些日志框架
3.在ThreadLocal中保存对象,但是并不去删除它
4.启动了线程,但没有停止它

解决方法可能就是对应的应用需要加一个 ServletContextListener ,然后在 contextDestroyed 方法里去把以上的事情做掉。比如如果你用到了jdbc,那么需要手动去注销jdbc。threadlocal的保存的对象把它们清空掉。等等等等。。。

要具体问题具体分析。当然也可以不做什么事情。其实也没有多大关系的。

这里的内存泄漏指的也是你在不重新启动tomcat的情况下,reload某一个应用,才会造成内存泄漏。所以你只要每次重启应用都是通过重启tomcat来的话不会造成任何影响。[/Quote]

+1
朱超ZhuChao.Tech 2012-08-04
  • 打赏
  • 举报
回复
http://sd.csdn.net/a/20120530/2806167.html

这篇文章中的 JProfiler 这款工具 我建议你用 非常棒!
dracularking 2012-08-03
  • 打赏
  • 举报
回复
这里列举了tomcat能处理的内存泄露类型
http://wiki.apache.org/tomcat/MemoryLeakProtection

关于由JDBC driver registration引起的memory leak是这样解释的:

If a webapp contains a JDBC driver (e.g. in WEB-INF/lib), the driver will be registered with the DriverManager when it is first used. When the application is stopped, the driver should be deregistered with DriverManager to avoid a classloader leak. Since applications usually forget this, tomcat helps by deregistering the driver.
dracularking 2012-08-03
  • 打赏
  • 举报
回复
[Quote=引用 17 楼 的回复:]

看下这个有用不
http://stackoverflow.com/questions/3320400/to-prevent-a-memory-leak-the-jdbc-driver-has-been-forcibly-unregistered
[/Quote]
楼主可以试下这里的第二个答案,看看能不能关闭第一个答案中所说的在webapp启动时与tomcat本身无关的、自动注册却不自动注销的驻/WEB-INF/lib中的JDBC4.0兼容驱动程序。
qybao 2012-08-03
  • 打赏
  • 举报
回复
[Quote=引用楼主 的回复:]
在关闭Tomcat的时候报了很多错,贴上错误代码

Java code


SEVERE: The web application [] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To preven……
[/Quote]
看错误提示是数据库驱动卸载不了,所以后面的线程池使用的资源释放不掉而关闭不了
看看log文件还有什么更详细的信息没有?

qybao 2012-08-03
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 的回复:]
关闭tomcat后,执行ps -ef | grep tomcat 还有很多进程
[/Quote]
你的tomcat都没关掉吧,都是启动tomcat的进程,能启动多个吗?端口什么的都冲突了,LZ试试看kill掉再重启
YAVA_2009 2012-08-03
  • 打赏
  • 举报
回复
顶一下,我好像也有这个问题。
以前是因为数据库链接什么的没有关闭,造成内存吃的很快,后来检查了一遍,好了一些。
现在消耗的没那么快了。
believefym 2012-08-03
  • 打赏
  • 举报
回复
看下这个有用不
http://stackoverflow.com/questions/3320400/to-prevent-a-memory-leak-the-jdbc-driver-has-been-forcibly-unregistered
是一格啊 2012-08-03
  • 打赏
  • 举报
回复
你把数据库连接池配置去掉,就用普通的数据库连接试试。如果不行那不一定是连接池的原因
大_爱 2012-08-03
  • 打赏
  • 举报
回复
有人知道这个都是什么吗?
大_爱 2012-08-03
  • 打赏
  • 举报
回复
关闭tomcat后,执行ps -ef | grep tomcat 还有很多进程
大_爱 2012-08-03
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 的回复:]

你的问题只是内存无限制增长,跟你贴的日志一毛钱关系都没有。 自己检查下线程里都干了啥吧
[/Quote]

看看日志估计会有帮助的呀
nickycheng 2012-08-03
  • 打赏
  • 举报
回复
你的问题只是内存无限制增长,跟你贴的日志一毛钱关系都没有。 自己检查下线程里都干了啥吧
大_爱 2012-08-03
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 的回复:]

jstack 可以查看内存泄露
JProbe 好像也不错,但好像是收费的。http://www.ibm.com/developerworks/library/j-leaks/
[/Quote]

谢谢,我去下载试试。
大_爱 2012-08-03
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 的回复:]

Tomcat7是吧? 它增加了一个内存泄漏的检查,主要是判断web应用重载时,类加载器中所有对象的引用都释放干净。

一般出现提示可能的原因:
1.JDBC驱动注册
2.一些日志框架
3.在ThreadLocal中保存对象,但是并不去删除它
4.启动了线程,但没有停止它

解决方法可能就是对应的应用需要加一个 ServletContextListener ,然后在 context……
[/Quote]

我现在不知道是不是Tomcat7了,
我是用的JDBC连接数据库,打印了很多日志,用log4j
用了一个线程池,启动了几个线程没有停止

这些如果不照成内存泄漏也不存在,但是现在内存泄漏很严重,Tomcat运行一会,机器就很慢了,2G的内存一会就没了。
brightyq 2012-08-03
  • 打赏
  • 举报
回复
jstack 可以查看内存泄露
JProbe 好像也不错,但好像是收费的。http://www.ibm.com/developerworks/library/j-leaks/
加载更多回复(8)

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧