java - 如何通过 start-stop-daemon 优雅地关闭 Spring Boot 应用程序

标签 java multithreading spring-boot start-stop-daemon

<分区>

我们有一个多线程的 Spring Boot 应用程序,它作为守护进程运行在 Linux 机器上。当我尝试像这样通过 start-stop-daemon 停止应用程序时

start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME

SIGTERM 信号被发送,应用程序立即结束。但是我希望应用程序等待,直到每个线程都完成它的工作。

有什么办法,如何管理收到 SIGTERM 信号时发生的事情?

最佳答案

Spring Boot 应用程序向 JVM 注册一个关闭 Hook ,以确保 ApplicationContext 在退出时正常关闭。创建实现 DisposableBean 或具有带有 @PreDestroy 注释的方法的 bean(或多个 bean)。此 bean 将在应用程序关闭时调用。

http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-application-exit

关于java - 如何通过 start-stop-daemon 优雅地关闭 Spring Boot 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36691355/

相关文章:

java - 如何在不使用 Collections.shuffle(...) 的情况下打乱字符串中的字符?

java - 如何在 Eclipse 中导出带有特定 list 文件和所需库提取的可运行 jar?

java - 如何在phonegap中实现幻灯片切换?

java - 线程不同时运行

java - 即使我正在调用 thread.interrupt() 线程也不会中断

spring - Sonar 提示 Spring Boot 配置

spring-boot - 如何在 Spring Boot 中配置 RabbitMQ 身份验证机制?

java - Camel Split EIP 和池中线程的使用似乎没有超过最小线程

c# - 多线程windows phone应用程序

java - 数据库更新后模型类出现问题,