内存泄漏Tomcat进程意外退出This is very likely to create a memory leak

内存泄漏的事情,一个月让我碰到了两次,心累~

先看报错日志:

03-Jul-2018 20:22:55.335 WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesJdbc The web application [onlineStudyManager] registered the JDBC driver [com.alibaba.druid.proxy.DruidDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
03-Jul-2018 20:22:55.335 WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesJdbc The web application [onlineStudyManager] 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.
03-Jul-2018 20:22:55.336 WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [onlineStudyManager] 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. Stack trace of thread:
 java.lang.Object.wait(Native Method)
 java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143)
 com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:64)
 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
 java.lang.Thread.run(Thread.java:748)
03-Jul-2018 20:22:55.337 WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [onlineStudyManager] appears to have started a thread named [commons-pool-evictor-thread] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 sun.misc.Unsafe.park(Native Method)
 java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
 java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2078)
 java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1093)
 java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:809)
 java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
 java.lang.Thread.run(Thread.java:748)
03-Jul-2018 20:22:55.338 SEVERE [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [onlineStudyManager] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@21fa2b27]) and a value of type [com.alibaba.druid.wall.spi.WallVisitorUtils.WallTopStatementContext] (value [com.alibaba.druid.wall.spi.WallVisitorUtils$WallTopStatementContext@55e7173a]) 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.

从日志中找出关键信息
Stack trace of thread: java.lang.Object.wait(Native Method) sun.misc.Unsafe.park(Native Method)

这两个信息,并不是由于代码层面出现的问题,这就让我很头疼了

既然不是代码的问题,为何tomcat会意外退出

搜遍google,看到一篇文章 Tomcat进程意外退出的问题分析

情况类似,感谢提供的资料,具体的内容博主也要多次去学习理解。

但具体的原因已经找到了:

为了方便部署,写了一个简单的linux上的脚本进行部署,脚本部署的流程大概是:

找到对应程序进程 -> 杀掉进程 -> jar包移动 -> 启动tomcat -> 查看日志

同样的,看报错时间是我昨天下班的关电脑的时间,因为走得急,并没有退出日志就关闭了ssh

附上脚本(看看就好,写得简陋,很多地方没有做处理):

#! /bin/bash
echo 'kill tomcat'
ps -ef | grep apache-tomcat-8.5.31-study | grep -v grep | awk '{print $2}' | xargs kill -9
echo "kill success"
echo "============"
echo "copy jar"
cd /usr/local/tomcat/apache-tomcat-8.5.31-study/webapps/onlineStudy/
rm -rf WEB-INF
rm -rf onlineStudy_dev.jar
cd ~
cd root/
cp onlineStudy_dev.jar /usr/local/tomcat/apache-tomcat-8.5.31-study/webapps/onlineStudy/
cd /usr/local/tomcat/apache-tomcat-8.5.31-study/webapps/onlineStudy/
jar -xvf onlineStudy_dev.jar
echo "copy success"
echo "============"
echo "tomcat start"
cd ../../
cd bin/
./startup.sh
cd ../logs
tail -f catalina.out

你可能感兴趣的:(linux,java)