diff --git a/src/main/java/io/hyperfoil/tools/qdup/shell/AbstractShell.java b/src/main/java/io/hyperfoil/tools/qdup/shell/AbstractShell.java index facf76ff..219f2ce4 100644 --- a/src/main/java/io/hyperfoil/tools/qdup/shell/AbstractShell.java +++ b/src/main/java/io/hyperfoil/tools/qdup/shell/AbstractShell.java @@ -600,22 +600,28 @@ public void addShObserver(String name, Consumer consumer) { addShObserver(name,(output,promptName)->consumer.accept(output)); } public void addShObserver(String name, BiConsumer consumer) { - shObservers.put(name, consumer); + synchronized (AbstractShell.class) { + shObservers.put(name, consumer); + } } public void removeShObserver(String name) { - shObservers.remove(name); + synchronized (AbstractShell.class) { + shObservers.remove(name); + } } private void shObservers(String output,String promptName) { - shObservers.forEach((name,consumer)->{ - int v = c.getAndIncrement(); - logger.info("in: consumer.accept: {}x", v); - if (v == 15) { - logger.info("{}={}", name, output); - } - consumer.accept(output,promptName); - logger.info("out: consumer.accept: {}x", v); - }); + synchronized (AbstractShell.class) { + shObservers.forEach((name, consumer) -> { + int v = c.getAndIncrement(); + logger.info("in: consumer.accept: {}x", v); + if (v == 15) { + logger.info("{}={}", name, output); + } + consumer.accept(output, promptName); + logger.info("out: consumer.accept: {}x", v); + }); + } } public int permits() { return shellLock.availablePermits();