File tree 2 files changed +8
-5
lines changed
spring-boot-project/spring-boot/src
main/java/org/springframework/boot
test/java/org/springframework/boot
2 files changed +8
-5
lines changed Original file line number Diff line number Diff line change 16
16
17
17
package org .springframework .boot ;
18
18
19
+ import java .util .ArrayList ;
19
20
import java .util .Collections ;
20
21
import java .util .LinkedHashSet ;
22
+ import java .util .List ;
21
23
import java .util .Set ;
22
24
import java .util .WeakHashMap ;
23
25
import java .util .concurrent .TimeUnit ;
@@ -103,12 +105,13 @@ void deregisterFailedApplicationContext(ConfigurableApplicationContext applicati
103
105
public void run () {
104
106
Set <ConfigurableApplicationContext > contexts ;
105
107
Set <ConfigurableApplicationContext > closedContexts ;
106
- Set <Handler > handlers ;
108
+ List <Handler > handlers ;
107
109
synchronized (SpringApplicationShutdownHook .class ) {
108
110
this .inProgress = true ;
109
111
contexts = new LinkedHashSet <>(this .contexts );
110
112
closedContexts = new LinkedHashSet <>(this .closedContexts );
111
- handlers = new LinkedHashSet <>(this .handlers .getActions ());
113
+ handlers = new ArrayList <>(this .handlers .getActions ());
114
+ Collections .reverse (handlers );
112
115
}
113
116
contexts .forEach (this ::closeAndWait );
114
117
closedContexts .forEach (this ::closeAndWait );
Original file line number Diff line number Diff line change @@ -207,7 +207,7 @@ void deregistersFailedContext() {
207
207
}
208
208
209
209
@ Test
210
- void handlersRunInDeterministicOrder () {
210
+ void handlersRunInDeterministicOrderFromLastRegisteredToFirst () {
211
211
TestSpringApplicationShutdownHook shutdownHook = new TestSpringApplicationShutdownHook ();
212
212
Runnable r1 = mock (Runnable .class );
213
213
Runnable r2 = mock (Runnable .class );
@@ -217,9 +217,9 @@ void handlersRunInDeterministicOrder() {
217
217
shutdownHook .getHandlers ().add (r3 );
218
218
shutdownHook .run ();
219
219
InOrder ordered = inOrder (r1 , r2 , r3 );
220
- ordered .verify (r2 ).run ();
221
- ordered .verify (r1 ).run ();
222
220
ordered .verify (r3 ).run ();
221
+ ordered .verify (r1 ).run ();
222
+ ordered .verify (r2 ).run ();
223
223
ordered .verifyNoMoreInteractions ();
224
224
}
225
225
You can’t perform that action at this time.
0 commit comments