java - Tomcat停止前等待某个函数运行结束的问题
黄舟
黄舟 2017-04-18 10:38:15
[Java讨论组]
黄舟
黄舟

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

全部回复(3)
阿神

其实这个问题可以忽略的,我遇到过这个问题。当时找到的答案有:

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

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

我的是Spring程序,所注册了一个SmartLifecycle,在程序stop的时候调用:

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));

}

如果你是Servlet的话,应该也有类似的Listener,在Listener里干这件事情就行了。

PHP中文网


非法访问看一下你的tomcat的权限是否打开

伊谢尔伦

问题产生的原因是这样的,因为netty是异步关闭的,所以tomcat的servlet关闭了之后,netty其实还没有关闭,所以就爆出这个错误。只要把netty设置为同步关闭就可以了。但是现在同步关闭的时候还是会有一个警告:

严重 [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.

不知该从哪里入手。。。

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号