Skip to content

Commit c5c8680

Browse files
committed
Make LifeCycleManager.stopAll more threadsafe
1 parent 6ec3c67 commit c5c8680

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/main/java/net/logstash/logback/LifeCycleManager.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import java.util.Collections;
1717
import java.util.HashSet;
18+
import java.util.Iterator;
1819
import java.util.Set;
1920
import java.util.concurrent.ConcurrentHashMap;
2021

@@ -76,14 +77,14 @@ public boolean stop(LifeCycle lifeCycle) {
7677
public Set<LifeCycle> stopAll() {
7778
Set<LifeCycle> stopped = new HashSet<>();
7879

79-
for (LifeCycle lifeCycle : started) {
80+
for (Iterator<LifeCycle> iterator = started.iterator(); iterator.hasNext(); ) {
81+
LifeCycle lifeCycle = iterator.next();
8082
if (lifeCycle.isStarted()) {
8183
lifeCycle.stop();
8284
stopped.add(lifeCycle);
8385
}
86+
iterator.remove();
8487
}
85-
86-
started.clear();
8788
return Collections.unmodifiableSet(stopped);
8889
}
8990

0 commit comments

Comments
 (0)