title: Java volatile variable question
body: <p>Reading this <a href="http://www.dzone.com/links/immutable_data_structures_in_concurrent_java_appl.html?ref=ps" rel="noreferrer">DZone article</a> about Java concurrency I was wondering if the following code:</p>
  
  <pre><code>
      private volatile List list;
      private final Lock lock = new ReentrantLock();
  
      public void update(List newList) {
          ImmutableList l = new ImmutableList().addAll(newList);
          lock.lock();
          list = l;
          lock.unlock();
      }
  
      public List get() {
          return list;
      }
  </code></pre>
  
  <p>is equivalent to:</p>
  
  <pre><code>
      private volatile List list;
  
      public void update(List newList) {
          ImmutableList l = new ImmutableList().addAll(newList); 
          list = l;
      }
  
      public List get() {
          return list;
      }
  </code></pre>
  
  <p>The try { } finally { } block was omitted for brevity. I assume the ImmutableList class to be a truly immutable data structure that holds its own data, such  as the one provided in the google-collections library. Since the list variable is volatile and basically what's going on is a copy-on-the-fly, isn't it safe to just skip on using locks?</p>