title: what are the concern regarding simultaneous read and write to a file?
body: <p>consider the following scenario:</p>
  
  <ol>
  <li>Process 1 (<strong>Writer</strong>) continuously appends a line to a file ( <strong>sharedFile.txt</strong> )</li>
  <li>Process 2 (<strong>Reader</strong>) continuously reads a line from <strong>sharedFile.txt</strong> </li>
  </ol>
  
  <p>my questions are:</p>
  
  <p>In java is it possible that :</p>
  
  <ol>
  <li><strong>Reader</strong> process somehow crashes <strong>Writer</strong> process  (i.e. breaks the process of Writer)?</li>
  <li><strong>Reader</strong> some how knows when to stop reading the file  purely based on the file stats  (Reader doesn't know if others are writing to the file)?</li>
  </ol>
  
  <p>to demonsterate </p>
  
  <p>Process one (<strong>Writer</strong>):</p>
  
  <pre><code>...
  while(!done){
   String nextLine;//process the line
   writeLine(nextLine);
   ...
  }
  ...
  </code></pre>
  
  <p>Process Two (<strong>Reader</strong>):</p>
  
  <pre><code>...
  while(hasNextLine()){
    String nextLine= readLine();
    ...
  }
  ...
  </code></pre>
  
  <p><strong>NOTE:</strong></p>
  
  <p><strong>Writer</strong> Process has priority. so nothing must interfere with it.</p>