title: Java List Synchronization
body: <p>I have an ArrayList which is accessed by multiple threads. Main thread only clears the list and others add to it. I don't want the list get cleared while another thread is adding item to it. I want the list is locked while thread is adding item to it.</p>
  
  <p>this is the code of adding thread:</p>
  
  <pre><code>synchronized (items)
  {
      int length = jsonArray.length();
      if ((length &gt; 0)) for (int i = 0; i &lt; length; i++)
      {
          items.add(new Item(jsonArray.getJSONObject(i)));
      }
  }
  </code></pre>
  
  <p>But I don't use synchronized block for clearing. Is synchronized block necessary for clear too?</p>