关闭tomcat时 log4j2 报错: sun.misc.Unsafe.park(Native Method)

异常信息:

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)

新项目使用log4j2+springmvc的方式,但是报这个错,查了很多资料,原因是log4j2-2.6开始引入shutdown(),在2.6中,如果web app卸载时没有进行shutdown(),tomcat会发布内存泄漏风险的告警。

解决方式是引入log4j2-web.jar,但是我这边引入后并没有解决,又google到处找方法,最后在一个同样出问题的帖子里找到了个方法可以解决

在web.xml里加入下边代码块,要放在spring相关配置前边

  
    org.apache.logging.log4j.web.Log4jServletContextListener
  
  
    isLog4jAutoInitializationDisabled
    true
  

国外问题地址

你可能感兴趣的:(关闭tomcat时 log4j2 报错: sun.misc.Unsafe.park(Native Method))