title: Synchronize write access to Volatile field (Cheap read-write block)
body: <p>Let's say I have the following class that will be read heavily, but only written to occasionally.  It will be used in a multi-threaded web app, so it needs to be thread safe:</p>
  
  <pre><code>public class Foo {
      private volatile String foo;
      public String getFoo() {
          return foo;
      }
      public synchronized String setFoo(String in) {
          this.foo = in;
      }
  }
  </code></pre>
  
  <p>Java Concurrency (<a href="http://www.ibm.com/developerworks/java/library/j-jtp06197/index.html">http://www.ibm.com/developerworks/java/library/j-jtp06197/index.html</a>) states that this is a fragile way to protect write access while improving read access.  What is a stronger alternative to this pattern?  Or any alternative if foo will need to mutable in a read-heavy environment?  Thank you.</p>