如何通过 start-stop-daemon 优雅地关闭 Spring Boot 应用程序 [英] How to gracefuly shutdown a Spring Boot application by start-stop-daemon

查看:36
本文介绍了如何通过 start-stop-daemon 优雅地关闭 Spring Boot 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

We have a multithreaded Spring Boot Application, which runs on Linux machine as a daemon. When I try to stop the application by start-stop-daemon like this

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

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

The SIGTERM signal is sent and application immetiately ends. However I want the application to wait, until every thread finishes it's work.

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

Is there any way, how to manage what happens, when SIGTERM signal is received?

推荐答案

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

Spring Boot app registers a shutdown hook with the JVM to ensure that the ApplicationContext is closed gracefully on exit. Create bean (or beans) that implements DisposableBean or has method with @PreDestroy annotation. This bean will be invoked on app shutdown.

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

这篇关于如何通过 start-stop-daemon 优雅地关闭 Spring Boot 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆