title: How to simulate ConcurrentModificationException in own class?
body: <p>I have been reading "Effective Java" <strong>Item 60</strong>, which is "Favor the use of standard exceptions".</p>
  
  <blockquote>
    <p>Another general-purpose exception worth knowing about is ConcurrentModificationException. This exception should be thrown if an object that was designed for use by a single thread or with external synchronization <strong>detects</strong> that it is being <strong>concurrently modified.</strong> </p>
  </blockquote>
  
  <p>Normally people face with <code>CME</code> when they try remove from a collection while looping.</p>
  
  <p>But in here I am interested about what would be a <strong>concise example on detecting a concurrent modification on self-implemented class object?</strong></p>
  
  <p>I expect it to be something like synchronizing on internal object and related boolean flag, if another thread confronts the flag being false, then throwing exception.</p>
  
  <p>For a simple research I have found in source of <code>ArrayList</code>:</p>
  
  <pre><code> final void checkForComodification() {
       if (modCount != expectedModCount)
           throw new ConcurrentModificationException();
   }
  </code></pre>
  
  <p>but the principle behind how <code>modCount</code> is maintained. I cannot find where it is being decremented.</p>