在当前互联网市场中,服务器开发中springboot引领潮流。很多开发者都异常喜欢这一框架用作开发!
在我身边有许许多多开发者在停止springboot程序时都使用 kill -9 PID命令,但是这一命令只能用在单个执行单元项目停止,但是现在的项目中不可能没有复杂操作数据业务,所以这样停止程序的行为很危险,应该在所有线程执行完毕后才可以停止程序。
作为成熟的框架,springboot团队早就想到这一点,故而提供了springboot actuator shutdown 功能,其实现方法如下:
1,在pom中加入依赖 <!-- 引入Actuator监控依赖 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
2,在springboot配置文件中配置 actuator shutdown
# 配置actuator shutdown
management: endpoint: shutdown: enabled: true endpoints: web: exposure: include: "*" 3,调用actuator shutdown
curl -X POST http://${ip}:${port}/actuator/shutdown
1,启动项目
2,停止项目
3,在停止前等待所有进程执行完毕
4,在所有线程执行完毕后停止程序
5,在生产中要对此接口进行身份认证!!!!!!