I have the following class:
public class AggregationController { private HashMap<String, TreeMap<Integer, String>> messages; private HashMap<String, Integer> counters; Boolean buildAggregateReply; private boolean isAggregationStarted; private static HashMap<String, AggregationController> instances = new HashMap<String, AggregationController>(); private AggregationController() throws MbException{ messages = new HashMap<String, TreeMap<Integer,String>>(); counters = new HashMap<String, Integer>(); buildAggregateReply = true; isAggregationStarted = false; } public static synchronized AggregationController getInstance(String id) throws MbException{ if(instances.get(id) == null) instances.put(id, new AggregationController()); return instances.get(id); }
I thought this was enough to avoid concurrent access, but I got this error:
HashMap.java checkConcurrentMod java.util.HashMap$AbstractMapIterator java.util.ConcurrentModificationException Unhandled exception in plugin method java.util.ConcurrentModificationException
I have 10 threads using this class, and it throws this error about once every 100,000 calls.
What is wrong with this single?
source share