Skip to content

Commit 0ce1ef9

Browse files
committed
Polishing (aligned with 6.0.x)
1 parent e26ea00 commit 0ce1ef9

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

Diff for: spring-context/src/main/java/org/springframework/context/support/DefaultLifecycleProcessor.java

+14-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -45,7 +45,11 @@
4545
import org.springframework.util.Assert;
4646

4747
/**
48-
* Default implementation of the {@link LifecycleProcessor} strategy.
48+
* Spring's default implementation of the {@link LifecycleProcessor} strategy.
49+
*
50+
* <p>Provides interaction with {@link Lifecycle} and {@link SmartLifecycle} beans in
51+
* groups for specific phases, on startup/shutdown as well as for explicit start/stop
52+
* interactions on a {@link org.springframework.context.ConfigurableApplicationContext}.
4953
*
5054
* @author Mark Fisher
5155
* @author Juergen Hoeller
@@ -145,13 +149,13 @@ private void startBeans(boolean autoStartupOnly) {
145149

146150
lifecycleBeans.forEach((beanName, bean) -> {
147151
if (!autoStartupOnly || (bean instanceof SmartLifecycle && ((SmartLifecycle) bean).isAutoStartup())) {
148-
int phase = getPhase(bean);
149-
phases.computeIfAbsent(
150-
phase,
151-
p -> new LifecycleGroup(phase, this.timeoutPerShutdownPhase, lifecycleBeans, autoStartupOnly)
152+
int startupPhase = getPhase(bean);
153+
phases.computeIfAbsent(startupPhase,
154+
phase -> new LifecycleGroup(phase, this.timeoutPerShutdownPhase, lifecycleBeans, autoStartupOnly)
152155
).add(beanName, bean);
153156
}
154157
});
158+
155159
if (!phases.isEmpty()) {
156160
phases.values().forEach(LifecycleGroup::start);
157161
}
@@ -191,6 +195,7 @@ private void doStart(Map<String, ? extends Lifecycle> lifecycleBeans, String bea
191195
private void stopBeans() {
192196
Map<String, Lifecycle> lifecycleBeans = getLifecycleBeans();
193197
Map<Integer, LifecycleGroup> phases = new HashMap<>();
198+
194199
lifecycleBeans.forEach((beanName, bean) -> {
195200
int shutdownPhase = getPhase(bean);
196201
LifecycleGroup group = phases.get(shutdownPhase);
@@ -200,6 +205,7 @@ private void stopBeans() {
200205
}
201206
group.add(beanName, bean);
202207
});
208+
203209
if (!phases.isEmpty()) {
204210
List<Integer> keys = new ArrayList<>(phases.keySet());
205211
keys.sort(Collections.reverseOrder());
@@ -314,6 +320,8 @@ protected int getPhase(Lifecycle bean) {
314320
/**
315321
* Helper class for maintaining a group of Lifecycle beans that should be started
316322
* and stopped together based on their 'phase' value (or the default value of 0).
323+
* The group is expected to be created in an ad-hoc fashion and group members are
324+
* expected to always have the same 'phase' value.
317325
*/
318326
private class LifecycleGroup {
319327

0 commit comments

Comments
 (0)