Skip to content

Commit 6257dc8

Browse files
committed
Merge branch '3.2.x'
See gh-40743
2 parents 7f6a99c + 5db9f59 commit 6257dc8

File tree

1 file changed

+9
-14
lines changed
  • spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty

1 file changed

+9
-14
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/GracefulShutdown.java

+9-14
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
import org.springframework.boot.web.server.GracefulShutdownCallback;
3131
import org.springframework.boot.web.server.GracefulShutdownResult;
32-
import org.springframework.core.log.LogMessage;
3332
import org.springframework.util.ReflectionUtils;
3433

3534
/**
@@ -46,7 +45,7 @@ final class GracefulShutdown {
4645

4746
private final Supplier<Integer> activeRequests;
4847

49-
private volatile boolean shuttingDown = false;
48+
private volatile boolean aborted = false;
5049

5150
GracefulShutdown(Server server, Supplier<Integer> activeRequests) {
5251
this.server = server;
@@ -55,12 +54,11 @@ final class GracefulShutdown {
5554

5655
void shutDownGracefully(GracefulShutdownCallback callback) {
5756
logger.info("Commencing graceful shutdown. Waiting for active requests to complete");
57+
new Thread(() -> awaitShutdown(callback), "jetty-shutdown").start();
5858
boolean jetty10 = isJetty10();
5959
for (Connector connector : this.server.getConnectors()) {
6060
shutdown(connector, !jetty10);
6161
}
62-
this.shuttingDown = true;
63-
new Thread(() -> awaitShutdown(callback), "jetty-shutdown").start();
6462

6563
}
6664

@@ -97,19 +95,16 @@ private boolean isJetty10() {
9795
}
9896

9997
private void awaitShutdown(GracefulShutdownCallback callback) {
100-
while (this.shuttingDown && this.activeRequests.get() > 0) {
98+
while (!this.aborted && this.activeRequests.get() > 0) {
10199
sleep(100);
102100
}
103-
this.shuttingDown = false;
104-
long activeRequests = this.activeRequests.get();
105-
if (activeRequests == 0) {
106-
logger.info("Graceful shutdown complete");
107-
callback.shutdownComplete(GracefulShutdownResult.IDLE);
101+
if (this.aborted) {
102+
logger.info("Graceful shutdown aborted with one or more requests still active");
103+
callback.shutdownComplete(GracefulShutdownResult.REQUESTS_ACTIVE);
108104
}
109105
else {
110-
logger.info(LogMessage.format("Graceful shutdown aborted with %d request%s still active", activeRequests,
111-
(activeRequests == 1) ? "" : "s"));
112-
callback.shutdownComplete(GracefulShutdownResult.REQUESTS_ACTIVE);
106+
logger.info("Graceful shutdown complete");
107+
callback.shutdownComplete(GracefulShutdownResult.IDLE);
113108
}
114109
}
115110

@@ -123,7 +118,7 @@ private void sleep(long millis) {
123118
}
124119

125120
void abort() {
126-
this.shuttingDown = false;
121+
this.aborted = true;
127122
}
128123

129124
}

0 commit comments

Comments
 (0)