java - Tomcat停止前等待某个函数运行结束的问题
黄舟
黄舟 2017-04-18 10:38:15
0
3
894
黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(3)
阿神

In fact, this problem can be ignored. I have encountered this problem. The answers I found at that time were:

  1. https://github.com/relayrides...

  2. https://github.com/netty/nett...

Mine is a Spring program, and a SmartLifecycle is registered, which is called when the program stops:

try {

  GlobalEventExecutor.INSTANCE.awaitInactivity(5L, TimeUnit.SECONDS);
  LOGGER.info("Close {}", GlobalEventExecutor.class.getName());

} catch (Exception e) {

  LOGGER.warn("Error happened when close {}", GlobalEventExecutor.class.getName());
  LOGGER.warn(ExceptionUtils.getStackTrace(e));

}

try {

  ThreadDeathWatcher.awaitInactivity(5L, TimeUnit.SECONDS);
  LOGGER.info("Close {}", ThreadDeathWatcher.class.getName());

} catch (Exception e) {

  LOGGER.warn("Error happened when close {}", ThreadDeathWatcher.class.getName());
  LOGGER.warn(ExceptionUtils.getStackTrace(e));

}

If you are a Servlet, you should have a similar Listener. Just do this in the Listener.

洪涛


If you access illegally, check whether the permissions of your tomcat are open

伊谢尔伦

The reason for the problem is that because netty is closed asynchronously, after the tomcat servlet is closed, netty has not actually been closed, so this error occurs. Just set netty to sync off. But now there is still a warning when synchronization is turned off:

严重 [localhost-startStop-1] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [electric] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@6c9a20a]) and a value of type [io.netty.util.internal.InternalThreadLocalMap] (value [io.netty.util.internal.InternalThreadLocalMap@59404c7b]) 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.

I don’t know where to start. . .

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template