|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2018 the original author or authors. |
| 2 | + * Copyright 2002-2020 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
25 | 25 | import java.util.List;
|
26 | 26 | import java.util.Map;
|
27 | 27 | import java.util.Set;
|
| 28 | +import java.util.TreeMap; |
28 | 29 | import java.util.concurrent.CountDownLatch;
|
29 | 30 | import java.util.concurrent.TimeUnit;
|
30 | 31 |
|
@@ -139,24 +140,20 @@ public boolean isRunning() {
|
139 | 140 |
|
140 | 141 | private void startBeans(boolean autoStartupOnly) {
|
141 | 142 | Map<String, Lifecycle> lifecycleBeans = getLifecycleBeans();
|
142 |
| - Map<Integer, LifecycleGroup> phases = new HashMap<>(); |
| 143 | + Map<Integer, LifecycleGroup> phases = new TreeMap<>(); |
| 144 | + |
143 | 145 | lifecycleBeans.forEach((beanName, bean) -> {
|
144 | 146 | if (!autoStartupOnly || (bean instanceof SmartLifecycle && ((SmartLifecycle) bean).isAutoStartup())) {
|
| 147 | + |
145 | 148 | int phase = getPhase(bean);
|
146 |
| - LifecycleGroup group = phases.get(phase); |
147 |
| - if (group == null) { |
148 |
| - group = new LifecycleGroup(phase, this.timeoutPerShutdownPhase, lifecycleBeans, autoStartupOnly); |
149 |
| - phases.put(phase, group); |
150 |
| - } |
151 |
| - group.add(beanName, bean); |
| 149 | + phases.computeIfAbsent( |
| 150 | + phase, |
| 151 | + p -> new LifecycleGroup(phase, this.timeoutPerShutdownPhase, lifecycleBeans, autoStartupOnly) |
| 152 | + ).add(beanName, bean); |
152 | 153 | }
|
153 | 154 | });
|
154 | 155 | if (!phases.isEmpty()) {
|
155 |
| - List<Integer> keys = new ArrayList<>(phases.keySet()); |
156 |
| - Collections.sort(keys); |
157 |
| - for (Integer key : keys) { |
158 |
| - phases.get(key).start(); |
159 |
| - } |
| 156 | + phases.forEach((key, value) -> value.start()); |
160 | 157 | }
|
161 | 158 | }
|
162 | 159 |
|
|
0 commit comments