tomcat停止了,只是停止了容器,可能还有java线程没停止,导致tomcat进程还在
- 拿到tomcat进程pid
ps -ef|grep tomcat 得到pid 31057
- 查看java进程,到底后台还在执行什么
jstack -F 31057 >> run.log
主要观察几种状态:
死锁,Deadlock(重点关注)
执行中,Runnable
等待资源,Waiting on condition(重点关注)
等待获取监视器,Waiting on monitor entry(重点关注)
暂停,Suspended
对象等待中,Object.wait() 或 TIMED_WAITING
阻塞,Blocked(重点关注)
停止,Parked
#50条 Ehcache缓存 停止后还在大量增加 Thread 26792: (state = BLOCKED) - java.lang.Thread.sleep(long) @bci=0 (Compiled frame; information may be imprecise) - net.sf.ehcache.distribution.RMIAsynchronousCacheReplicator.replicationThreadMain() @bci=8, line=108 (Compiled frame) - net.sf.ehcache.distribution.RMIAsynchronousCacheReplicator.access$0(net.sf.ehcache.distribution.RMIAsynchronousCacheReplicator) @bci=1, line=103 (Interpreted frame) - net.sf.ehcache.distribution.RMIAsynchronousCacheReplicator$ReplicationThread.run() @bci=4, line=376 (Interpreted frame) #41条 Ehcache缓存 Thread 26793: (state = BLOCKED) - java.lang.Thread.sleep(long) @bci=0 (Compiled frame; information may be imprecise) - net.sf.ehcache.store.DiskStore.spoolAndExpiryThreadMain() @bci=20, line=669 (Compiled frame) - net.sf.ehcache.store.DiskStore.access$2(net.sf.ehcache.store.DiskStore) @bci=1, line=662 (Interpreted frame) - net.sf.ehcache.store.DiskStore$SpoolAndExpiryThread.run() @bci=4, line=1170 (Interpreted frame) |
通过分析日志发现大量的Ehcache缓存在阻塞,怀疑可能是Ehcache没停导致tomcat的进程一直都在
PS : 在实际运行中,往往一次 dump的信息,还不足以确认问题。建议产生三次 dump信息,如果每次 dump都指向同一个问题,我们才确定问题的典型性。也就是多进行几次线程快照,观察变化,查看问题所在。
- 查看项目,发现项目有使用到ehcache, 但是没配置停止时释放ehcache资源,配置上后,再停止tomcat时,后台没有进程
web.xml
<!-- 释放ehcache资源 -->
<listener> <listener-class>net.sf.ehcache.constructs.web.ShutdownListener</listener-class>
</listener>
<!--distributable /-->
欢迎参观我的个人网站