Newyorkcity
V2EX  ›  问与答

请问 springboot 有没有类似 @EventListener(ApplicationReadyEvent.class)但是监听的是程序退出的功能?想规定在程序退出的时候做点事。谢谢

  •  
  •   Newyorkcity · Mar 4, 2020 · 3116 views
    This topic created in 2454 days ago, the information mentioned may be changed or developed.
    谢谢
    fmumu
    fmumu
    Mar 4, 2020 via Android❤️1
    1
    应该有容器销毁事件的吧,或者自己注册个 shutdownHook
    Sharuru
    Sharuru
    Mar 4, 2020❤️1
    2
    你要了解的可能是 Graceful Shutdown。
    随便找了一篇文章可以参考一下: https://dzone.com/articles/graceful-shutdown-spring-boot-applications
    MoHen9
    MoHen9
    Mar 4, 2020 via Android❤️1
    3
    有,是 interface,叫什么 ApplicationEvent,匹配对应的泛型类型,好像叫这个名字,记不太清了
    nutting
    nutting
    Mar 4, 2020
    4
    有,这是 jvm 提供的
    nutting
    nutting
    Mar 4, 2020❤️1
    5
    还有 spring 本身也有容器生命周期检测,有这个注解
    DeadLion
    DeadLion
    Mar 4, 2020
    6
    kill -9 情况下 Graceful Shutdown 就没用了
    Newyorkcity
    Newyorkcity
    OP
    Mar 4, 2020
    7
    @nutting 请问是什么呢?
    @DeadLion 我是在 windows server 上跑,有一个 powershell 窗口,我把这个窗口关掉,算 kill -9 么?
    DeadLion
    DeadLion
    Mar 4, 2020❤️1
    8
    @Newyorkcity 这个还真不清楚,kill 是 Linux 上的命令,windows server 不知道能不能生效,搜了下也没看到有用的资料。
    nutting
    nutting
    Mar 4, 2020❤️1
    9
    Runtime.getRuntime().addShutdownHook
    zollum
    zollum
    Mar 4, 2020 via Android❤️1
    10
    ContextStoppedEvent 可以试下
    Vkery
    Vkery
    Mar 5, 2020
    11
    Runtime.getRuntime().addShutdownHook
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1825 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 05:30 · PVG 13:30 · LAX 21:30 · JFK 00:30
    ♥ Do have faith in what you're doing.