29
29
30
30
import org .springframework .boot .web .server .GracefulShutdownCallback ;
31
31
import org .springframework .boot .web .server .GracefulShutdownResult ;
32
- import org .springframework .core .log .LogMessage ;
33
32
import org .springframework .util .ReflectionUtils ;
34
33
35
34
/**
@@ -46,7 +45,7 @@ final class GracefulShutdown {
46
45
47
46
private final Supplier <Integer > activeRequests ;
48
47
49
- private volatile boolean shuttingDown = false ;
48
+ private volatile boolean aborted = false ;
50
49
51
50
GracefulShutdown (Server server , Supplier <Integer > activeRequests ) {
52
51
this .server = server ;
@@ -55,12 +54,11 @@ final class GracefulShutdown {
55
54
56
55
void shutDownGracefully (GracefulShutdownCallback callback ) {
57
56
logger .info ("Commencing graceful shutdown. Waiting for active requests to complete" );
57
+ new Thread (() -> awaitShutdown (callback ), "jetty-shutdown" ).start ();
58
58
boolean jetty10 = isJetty10 ();
59
59
for (Connector connector : this .server .getConnectors ()) {
60
60
shutdown (connector , !jetty10 );
61
61
}
62
- this .shuttingDown = true ;
63
- new Thread (() -> awaitShutdown (callback ), "jetty-shutdown" ).start ();
64
62
65
63
}
66
64
@@ -97,19 +95,16 @@ private boolean isJetty10() {
97
95
}
98
96
99
97
private void awaitShutdown (GracefulShutdownCallback callback ) {
100
- while (this .shuttingDown && this .activeRequests .get () > 0 ) {
98
+ while (! this .aborted && this .activeRequests .get () > 0 ) {
101
99
sleep (100 );
102
100
}
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 );
108
104
}
109
105
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 );
113
108
}
114
109
}
115
110
@@ -123,7 +118,7 @@ private void sleep(long millis) {
123
118
}
124
119
125
120
void abort () {
126
- this .shuttingDown = false ;
121
+ this .aborted = true ;
127
122
}
128
123
129
124
}
0 commit comments