title: How does a synchronized statement work in this case?
body: <p>Assume I have a class like this:</p>
  
  <pre><code>public class Server {
  
     public static void main(String[] args) {
  
        Map&lt;Integer, ServerThread&gt; registry = Collections.synchronizedMap(new LinkedHashMap&lt;Integer, ServerThread&gt;());
  
        ...
  
        while(true) {
           Socket socket = serverSocket.accept();
           ServerThread serverThread = new ServerThread(id, registry);
           registry.put(id, serverThread);
        }
     }
  }
  </code></pre>
  
  <p>Then:</p>
  
  <pre><code>public class ServerThread extends Thread {
  
     private Map&lt;Integer, ServerThread&gt; registry;
     private int id;
  
     public ServerThread(int id, Map&lt;Integer, ServerThread&gt; registry) {
        this.id = id;
        this.registry = registry;
     }
  
     ...
  
     private void notify() {
        synchronized(registry) {
           for(ServerThread serverThread : registry.values()) {
              serverThread.callSomePublicMethodOnThread();
           }
        }      
     }
  }
  </code></pre>
  
  <p>I just want to make sure that <code>registry</code> doesn't get modified while I am iterating over it. Does making it a synchronized map guarantee this behavior? Or do I need the <code>synchronized</code> statement. Will the synchronized statement behave like I expect it to?</p>
  
  <p>Thanks</p>