关闭springboot 但tomcat不关闭的情况下,Sentinel的监听服务(8719)还在运

关闭springboot 但tomcat不关闭的情况下,Sentinel的监听服务(8719)还在运行, 下次启动,因为8719端口被占用,所以会启动8720端口,这样就会有两个端口运行监听服务

原提问者GitHub用户zhangxuzhuang

展开
收起
云上静思 2023-05-19 16:22:18 187 发布于北京 分享
分享
版权
举报
1 条回答
写回答
取消 提交回答
  • 找到原因了,通过/shutdown的endpoint关闭应用时,因为Sentinel监听服务里有两个ExecutorService,里面的线程并未完全销毁,导致应用进程依然存活,监听服务依旧还在。

    在应用里定义一个listener监听SpringContext关闭事件,里面通过CommandCenter#stop停止Sentinel监听服务试试:

    @Component public class ApplicationShutDownListener implements ApplicationListener {

    private static final Logger LOGGER = LoggerFactory.getLogger(ApplicationShutDownListener.class);
    
    @Override
    public void onApplicationEvent(ContextClosedEvent contextClosedEvent) {
        try {
            LOGGER.info("spring context closed, stop sentinel commend center");
            CommandCenterProvider.getCommandCenter().stop();
        } catch (Exception e) {
            LOGGER.error("stop sentinel commend center error", e);
        }
    }
    

    }

    参考资料: springboot通过shutdown进程依然存活的问题:https://www.jianshu.com/p/7f76b8e1b6b8

    原回答者GitHub用户cdfive

    2023-05-19 22:43:40 举报
    赞同 评论

    评论

    全部评论 (0)

    登录后可评论

阿里云拥有国内全面的云原生产品技术以及大规模的云原生应用实践,通过全面容器化、核心技术互联网化、应用 Serverless 化三大范式,助力制造业企业高效上云,实现系统稳定、应用敏捷智能。拥抱云原生,让创新无处不在。

还有其他疑问?
咨询AI助理