Search code examples
javaconcurrencyconcurrentmodification

Is it possible that I get ConcurrentModificationException when all the methods in my program are synchronized?


I get a ConcurrentModificationException even though I made all the methods of the whole program synchronized (including static methods and the main method).

I don't have hidden iterators.

  1. How is that even possible?!
  2. What does it mean?
  3. How can I fix it?

Solution

    1. A ConcurrentModificationException can be caused by the same thread manipulating a collection while iterating over it
    2. It means don't change collections while iterating over them, except through the Iterator.remove() or ListIterator.add() methods
    3. see 2.