DefaultLifecycleProcessor properly handles count for dependent beans
Issue: SPR-16901
This commit is contained in:
@@ -252,7 +252,7 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor
|
||||
}
|
||||
}
|
||||
else if (bean instanceof SmartLifecycle) {
|
||||
// don't wait for beans that aren't running
|
||||
// Don't wait for beans that aren't running...
|
||||
latch.countDown();
|
||||
}
|
||||
}
|
||||
@@ -317,8 +317,6 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor
|
||||
*/
|
||||
private class LifecycleGroup {
|
||||
|
||||
private final List<LifecycleGroupMember> members = new ArrayList<>();
|
||||
|
||||
private final int phase;
|
||||
|
||||
private final long timeout;
|
||||
@@ -327,9 +325,13 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor
|
||||
|
||||
private final boolean autoStartupOnly;
|
||||
|
||||
private volatile int smartMemberCount;
|
||||
private final List<LifecycleGroupMember> members = new ArrayList<>();
|
||||
|
||||
private int smartMemberCount;
|
||||
|
||||
public LifecycleGroup(
|
||||
int phase, long timeout, Map<String, ? extends Lifecycle> lifecycleBeans, boolean autoStartupOnly) {
|
||||
|
||||
public LifecycleGroup(int phase, long timeout, Map<String, ? extends Lifecycle> lifecycleBeans, boolean autoStartupOnly) {
|
||||
this.phase = phase;
|
||||
this.timeout = timeout;
|
||||
this.lifecycleBeans = lifecycleBeans;
|
||||
@@ -337,10 +339,10 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor
|
||||
}
|
||||
|
||||
public void add(String name, Lifecycle bean) {
|
||||
this.members.add(new LifecycleGroupMember(name, bean));
|
||||
if (bean instanceof SmartLifecycle) {
|
||||
this.smartMemberCount++;
|
||||
}
|
||||
this.members.add(new LifecycleGroupMember(name, bean));
|
||||
}
|
||||
|
||||
public void start() {
|
||||
@@ -352,9 +354,7 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor
|
||||
}
|
||||
Collections.sort(this.members);
|
||||
for (LifecycleGroupMember member : this.members) {
|
||||
if (this.lifecycleBeans.containsKey(member.name)) {
|
||||
doStart(this.lifecycleBeans, member.name, this.autoStartupOnly);
|
||||
}
|
||||
doStart(this.lifecycleBeans, member.name, this.autoStartupOnly);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -369,13 +369,7 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor
|
||||
CountDownLatch latch = new CountDownLatch(this.smartMemberCount);
|
||||
Set<String> countDownBeanNames = Collections.synchronizedSet(new LinkedHashSet<>());
|
||||
for (LifecycleGroupMember member : this.members) {
|
||||
if (this.lifecycleBeans.containsKey(member.name)) {
|
||||
doStop(this.lifecycleBeans, member.name, latch, countDownBeanNames);
|
||||
}
|
||||
else if (member.bean instanceof SmartLifecycle) {
|
||||
// already removed, must have been a dependent
|
||||
latch.countDown();
|
||||
}
|
||||
doStop(this.lifecycleBeans, member.name, latch, countDownBeanNames);
|
||||
}
|
||||
try {
|
||||
latch.await(this.timeout, TimeUnit.MILLISECONDS);
|
||||
|
||||
Reference in New Issue
Block a user