ConcurentModificationException in Java HashMap
- by Bear
Suppose I have two methods in my classes, writeToMap() and processKey() and both methods are called by multiple threads. writeToMap is a method to write something in hashmap and processKey() is used to do sth based on the keySet of HashMap.
Inside processKey, I first copy the originalMap before getting the key set.
new HashMap<String, Map<String,String>(originalMap).get("xx").keySet();
But I am still getting ConcurrentModificationException even though I always copy the hashmap. Whats the problem?