开发者社区 > 云原生 > 正文

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

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

原提问者GitHub用户zhangxuzhuang

展开
收起
云上静思 2023-05-19 16:22:18 149 0
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
    赞同 展开评论 打赏

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

相关电子书

更多
阿里云容器 AHAS Sentinel 网关流控揭秘 立即下载
workshop专场-微服务专场-开发者动手实践营-微服务-使用Sentinel进行微服务流量控制 立即下载
Sentinel分布式系统下的流量防卫兵 立即下载