trying to circumvent the ConcurrentModificaationException thrown when pushing new messages

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2026-01-27 11:24:26 +01:00
parent e113d6389a
commit 6cab16b5bb

View File

@@ -3,6 +3,8 @@ package de.srsoftware.umbrella.messagebus;
import de.srsoftware.umbrella.messagebus.events.Event;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class MessageBus {
@@ -15,7 +17,7 @@ public class MessageBus {
new Thread(() -> { // TODO: use thread pool
try {
Thread.sleep(100);
listeners.parallelStream().forEach(l -> l.onEvent(event));
List.copyOf(listeners).parallelStream().forEach(l -> l.onEvent(event));
} catch (InterruptedException ignored) {
}
}).start();