title: Correct way to synchronize ArrayList in java
body: <p>I'm not sure if this is the correct way to synchronize my <code>ArrayList</code>.</p>
  
  <p>I have an <code>ArrayList</code> <code>in_queue</code> which is passed in from the <code>registerInQueue</code> function.</p>
  
  <pre><code>ArrayList&lt;Record&gt; in_queue = null;
  
  public void registerInQueue(ArrayList in_queue)
  {
      this.in_queue = in_queue;
  }
  </code></pre>
  
  <p>Now I'm trying to synchronize it. Is this sychronizing my <code>in_queue</code> object correctly?</p>
  
  <pre><code>List&lt;Record&gt; in_queue_list = Collections.synchronizedList(in_queue);
  
  synchronized (in_queue_list) {
      while (in_queue_list.size() &gt; 0) {
          in_queue_list.remove(0);
      }
  }
  </code></pre>