Space out smart lifecycle phases used for graceful shutdown

Previously, the web server was stopped in the last smart lifecycle
phase with graceful shutdown having begun in the previous phase.
This lack of space between the two phases and after the stop phase
made it hard to for other smart lifecycles to be part of the
graceful shutdown process.

This commit moves stop to 1024 phases before the final phase and
graceful shutdown a further 1024 phases before that, allowing
other smart lifecycles to run between graceful shutdown and stop
and also after stop.

Closes gh-31714
This commit is contained in:
Andy Wilkinson 2022-10-06 13:11:29 +01:00
parent 68e4aa232b
commit f2f4a4a40e
3 changed files with 5 additions and 3 deletions

View File

@ -31,7 +31,7 @@ public final class WebServerGracefulShutdownLifecycle implements SmartLifecycle
* {@link SmartLifecycle#getPhase() SmartLifecycle phase} in which graceful shutdown
* of the web server is performed.
*/
public static final int SMART_LIFECYCLE_PHASE = SmartLifecycle.DEFAULT_PHASE;
public static final int SMART_LIFECYCLE_PHASE = SmartLifecycle.DEFAULT_PHASE - 1024;
private final WebServer webServer;

View File

@ -16,6 +16,7 @@
package org.springframework.boot.web.reactive.context;
import org.springframework.boot.web.context.WebServerGracefulShutdownLifecycle;
import org.springframework.boot.web.server.WebServer;
import org.springframework.context.SmartLifecycle;
@ -54,7 +55,7 @@ class WebServerStartStopLifecycle implements SmartLifecycle {
@Override
public int getPhase() {
return Integer.MAX_VALUE - 1;
return WebServerGracefulShutdownLifecycle.SMART_LIFECYCLE_PHASE - 1024;
}
}

View File

@ -16,6 +16,7 @@
package org.springframework.boot.web.servlet.context;
import org.springframework.boot.web.context.WebServerGracefulShutdownLifecycle;
import org.springframework.boot.web.server.WebServer;
import org.springframework.context.SmartLifecycle;
@ -59,7 +60,7 @@ class WebServerStartStopLifecycle implements SmartLifecycle {
@Override
public int getPhase() {
return Integer.MAX_VALUE - 1;
return WebServerGracefulShutdownLifecycle.SMART_LIFECYCLE_PHASE - 1024;
}
}