简体   繁体   English

Spring 正常关机挂钩?

[英]Spring graceful shutdown hooks?

i am using Spring Boot 2.7 with server.shutdown=graceful .我正在使用 Spring Boot 2.7 和server.shutdown=graceful I have an issue with open SSE connections, as those do not terminate during the graceful shutdown.我对打开的 SSE 连接有疑问,因为这些连接在正常关闭期间不会终止。

I get the following:我得到以下信息:

2023-01-03 17:50:20.079  INFO 39014 --- [tomcat-shutdown] o.s.b.w.e.tomcat.GracefulShutdown        : Graceful shutdown aborted with one or more requests still active

I would like to terminate all the SSE connections during the graceful shutdown, so that the server can stop quicker, and not wait for the 30s timeout for connections that won't ever finish.我想在正常关闭期间终止所有 SSE 连接,以便服务器可以更快地停止,而不是等待永远不会完成的连接的 30 秒超时。

I tried using @PreDestroy on my bean, but it is invoked after the graceful shutdown, and thus doesn't work.我尝试在我的 bean 上使用@PreDestroy ,但它在正常关闭后被调用,因此不起作用。

Is there another Spring hook i could use to close the open SSE connections during the graceful shutdown?在正常关闭期间,我可以使用另一个 Spring 挂钩来关闭打开的 SSE 连接吗?

I managed to solve this by implementing SmartLifecycle on my controller. The stop method will be called during the shutdown phase, and cleanup can be done there.我设法通过在我的SmartLifecycle上实现 SmartLifecycle 来解决这个问题。 stop方法将在关闭阶段被调用,并且可以在那里进行清理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM