title: Synchronize shared file writing inside a JVM and across JVMs
body: <p>I have 2 distinct tomcat7 servers, on each the same web service is deployed. Each web service request has to update a file on a shared flesystem (typically a NAS).
  The file writing has to be synchronized to avoid conflict within the JVM of a tomcat server but also between JVM of the 2 servers.
  I tried several methods :</p>
  
  <p>=> A synchronized block for the file writing works only in the same JVM.</p>
  
  <p>=> A FileLock works for each JVM but not within the JVM of a server (a file can be locked only once).</p>
  
  <p>And how about using the Java7 nio file system ? can this help me ?
  What is the best way to solve this problem ?</p>
  
  <p>PS : sorry if my english is bad...</p>