ConcurentModificationException in Java HashMap

Posted by Bear on Stack Overflow See other posts from Stack Overflow or by Bear
Published on 2012-12-13T04:25:14Z Indexed on 2012/12/13 5:04 UTC
Read the original article Hit count: 149

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?

© Stack Overflow or respective owner

Related posts about java

Related posts about concurrency