title: How to debug ConcurrentModificationException?
body: <p>I encountered ConcurrentModificationException and by looking at it I can't see the reason why it's happening; the area throwing the exception and all the places modifying the collection are surrounded by </p>
  
  <pre><code>synchronized (this.locks.get(id)) {
    ...
  } // locks is a HashMap&lt;String, Object&gt;;
  </code></pre>
  
  <p>I tried to catch the the pesky thread but all I could nail (by setting a breakpoint in the exception) is that the throwing thread owns the monitor while the other thread (there are two threads in the program) sleeps.</p>
  
  <p><br>How should I proceed? What do you usually do when you encounter similar threading issues?</p>