title: Read Write File Through Multiple threads
body: <p>I want to read and write in a same file through threads.</p>
  
  <p>But the condition is when the first thread finishes reading only then the other thread should write.</p>
  
  <p>The solution that I proposed was:</p>
  
  <pre><code>class XYX {
  
    public void read(){
      synchronised(fileObj){
        //write the reading logic
      }
    }
  
    public void write(){
      synchronised(fileObj){
        //write the writing logic 
      }
    }
  }
  </code></pre>
  
  <p>Please let me know your ideas</p>
  
  <p>I want to retain this Ordering</p>
  
  <p>Reading - Writing - Reading - Writing - Reading -  so on</p>