異常信息:
06-Dec-2017 12:04:34.521 警告 [localhost-startStop-1] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [ROOT] appears to have started a thread named [Log4j2-TF-8-Scheduled-2] 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:1067)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1127)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
java.lang.Thread.run(Thread.java:745)
新項(xiàng)目使用log4j2+springmvc的方式绞绒,但是報(bào)這個(gè)錯(cuò)散吵,查了很多資料蜀踏,原因是log4j2-2.6開始引入shutdown()撬码,在2.6中儿倒,如果web app卸載時(shí)沒有進(jìn)行shutdown(),tomcat會發(fā)布內(nèi)存泄漏風(fēng)險(xiǎn)的告警呜笑。
解決方式是引入log4j2-web.jar夫否,但是我這邊引入后并沒有解決,又google到處找方法叫胁,最后在一個(gè)同樣出問題的帖子里找到了個(gè)方法可以解決
在web.xml里加入下邊代碼塊凰慈,要放在spring相關(guān)配置前邊
<listener>
<listener-class>org.apache.logging.log4j.web.Log4jServletContextListener</listener-class>
</listener>
<context-param>
<param-name>isLog4jAutoInitializationDisabled</param-name>
<param-value>true</param-value>
</context-param>