title: Rename a file that multiple processes are trying to use
body: <p>I have 2 applications running in parallel, both doing the following:</p>
  
  <ul>
  <li>check for file not containing "processed"</li>
  <li>process the file and then rename it to filename+processed</li>
  <li>for every file, only one application shall use it (on a first come first served basis)</li>
  </ul>
  
  <p>I get the files and I also lock them so the other application cannot process it. But when it comes to renaming the file I get a problem. To rename the file, wanted to use the File.renameTo function. However, for that to work, I have to release the lock on the file. But when I release the lock another process may try to use the file. Exactly that should not happen.</p>
  
  <p>Is there any way to prevent the application B from using the file between application A releasing the lock and finishing renaming the file?</p>
  
  <p><em><strong>EDIT</em></strong></p>
  
  <p>Some more information:</p>
  
  <ul>
  <li>File creation if the file doesn't exist has to be prevented.</li>
  <li>The file will be processed RandomAccessFile (with read and write permission; this creates a new file if it doesn't exist).</li>
  </ul>
  
  <p>Note: On linux, one can rename a file that is locked, so this problem doesn't occur there. However, on Windows a locked file cannot be renamed; I have to release the lock, then rename it. But the time, during which the lock is released creates enables other applications to see that the file is available and then they will try to use it.</p>