title: java concurrent Array List access
body: <p>I have an object which is a singleton. This object declares:</p>
  
  <pre><code>List&lt;Player&gt; players = new ArrayList&lt;Player&gt;();
  </code></pre>
  
  <p>The same object also specifies 4 operations on this arrayList:</p>
  
  <pre><code>public List&lt;Player&gt; getPlayers() {
  return players;
  } // the result of this method can be used in another object as an iterator (or maybe by index-access)
  </code></pre>
  
  <p>and </p>
  
  <pre><code>public void removePlayer(Player player) {
  players.remove(player);
  }
  
  public void addPlayer(Player player) {
  players.add(player);
  }
  
  public boolean isPresent(Player player) {
  if (players.constans(player)) {...
  }
  </code></pre>
  
  <p>Right now in the constructor I am doing it like that:</p>
  
  <pre><code>players = Collections.synchronizedList(new ArrayList&lt;Player&gt;());
  </code></pre>
  
  <p>But what is the CORRECT way to synchronize these methods. It seems like if I use iterator in another class, it will still through the concurrent modification exception. Does the exception happen if a 2 threads call at the same time the "remove" and "contains" method? There are many threads to access the singleton so I would like to know the method to do this with the minimum hit on performance.</p>