title: java method synchronization and read/write mutual exclusion
body: <p>I have two methods <code>read()</code> and <code>write()</code> as below in a class.</p>
  
  <pre><code>class Store
  {
  
    public void write()
    {
      // write to store;
    }
  
    public string  read()
    {
      // read from store;
    }
  }
  </code></pre>
  
  <p>1) The <code>Store</code> object is a singleton.</p>
  
  <p>2) I have a <code>Writer</code> class which will write to the store and several <code>Reader</code> classes which will read from the store at the same time.</p>
  
  <p>My requirement is that when the writer is writing to the store, all the readers should wait. i.e., when control is in <code>write()</code>, all the calls to <code>read()</code> should be blocked.  How do I achieve this? I have tried <code>synchronize(Store.class)</code> in the <code>write()</code> method, but doesn't seem like work for me.</p>