title: Should I synchronize a static volatile variable?
body: <p>There are a few questions on this subject, but most skirt around this issue because it's not the intent of the question. </p>
  
  <p>If I have a static volatile in my class:</p>
  
  <pre><code>private static volatile MyObj obj = null;
  </code></pre>
  
  <p>and in a method below I do:</p>
  
  <pre><code>public MyObj getMyObj() {
      if (obj == null) {
          obj = new MyObj();// costly initialisation
      }
      return obj;
  }
  </code></pre>
  
  <p>will I need to synchronize to ensure only one thread writes to the field, or will any writes be immediately visible to other threads evaluating the <code>obj == null</code> conditional?</p>
  
  <p>To put it another way: does volatile get you around having to synchronize access to writes on a static variable?</p>