Adding content to an ArrayList from another thread
<p>I have the main thread and ClientThread...
In the main thread when a user connects to the server it calls a method in the ClientThread</p>

<pre><code>    try {
        Socket socket = server.accept();
        clientThread.addClient(socket);
    } catch(Exception e) {
        e.printStackTrace();
    }
</code></pre>

<p>the method in the ClientThread adds content to an ArrayList</p>

<pre><code>public void addClient(Socket socket) {
    clientSockets.add(socket);
}
</code></pre>

<p>The ClientThread also runs this code on every frame:</p>

<pre><code>        for (Socket socket : clientSockets) {
            label.setText(socket.toString());
        }
</code></pre>

<p>for some reason i get this erron <code>java.util.ConcurrentModificationException</code> on this line <code>for (Socket socket : clientSockets) {</code>...</p>

<p>The question: <strong>why do i get this error, and how can i fix that?</strong></p>
