Skip to content

Commit

Permalink
Fix concurrent modification error when adding new configuration (#46)
Browse files Browse the repository at this point in the history
When adding a new configuration file to the directory the taskmanger failed with a concurrent modification error because it tried to remove an observer from the map it was iterating over. Apparently using keySet still keeps a reference to the map. Therefore it's wrapped by a new list.
  • Loading branch information
Hilbrand authored Sep 9, 2022
1 parent a640216 commit f4a10e2
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package nl.aerius.taskmanager.mq;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ScheduledExecutorService;
Expand Down Expand Up @@ -100,7 +101,7 @@ public void start() throws IOException {

@Override
public void shutdown() {
for (final String key : observers.keySet()) {
for (final String key : new ArrayList<>(observers.keySet())) {
removeObserver(key);
}
eventProducer.shutdown();
Expand Down

0 comments on commit f4a10e2

Please sign in to comment.