Skip to content

Commit f2f4a4a

Browse files
committed
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
1 parent 68e4aa2 commit f2f4a4a

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/context/WebServerGracefulShutdownLifecycle.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public final class WebServerGracefulShutdownLifecycle implements SmartLifecycle
3131
* {@link SmartLifecycle#getPhase() SmartLifecycle phase} in which graceful shutdown
3232
* of the web server is performed.
3333
*/
34-
public static final int SMART_LIFECYCLE_PHASE = SmartLifecycle.DEFAULT_PHASE;
34+
public static final int SMART_LIFECYCLE_PHASE = SmartLifecycle.DEFAULT_PHASE - 1024;
3535

3636
private final WebServer webServer;
3737

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/reactive/context/WebServerStartStopLifecycle.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.boot.web.reactive.context;
1818

19+
import org.springframework.boot.web.context.WebServerGracefulShutdownLifecycle;
1920
import org.springframework.boot.web.server.WebServer;
2021
import org.springframework.context.SmartLifecycle;
2122

@@ -54,7 +55,7 @@ public boolean isRunning() {
5455

5556
@Override
5657
public int getPhase() {
57-
return Integer.MAX_VALUE - 1;
58+
return WebServerGracefulShutdownLifecycle.SMART_LIFECYCLE_PHASE - 1024;
5859
}
5960

6061
}

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/context/WebServerStartStopLifecycle.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.boot.web.servlet.context;
1818

19+
import org.springframework.boot.web.context.WebServerGracefulShutdownLifecycle;
1920
import org.springframework.boot.web.server.WebServer;
2021
import org.springframework.context.SmartLifecycle;
2122

@@ -59,7 +60,7 @@ public boolean isRunning() {
5960

6061
@Override
6162
public int getPhase() {
62-
return Integer.MAX_VALUE - 1;
63+
return WebServerGracefulShutdownLifecycle.SMART_LIFECYCLE_PHASE - 1024;
6364
}
6465

6566
}

0 commit comments

Comments
 (0)