title: Read/write to XML file simultaneously in a Filelock using JAXB
body: <p><em>I have an XML file (in question) is used by process across multiple JVM. At one point of time, multiple process access the same file and writes to it. And i want the updated information to be read after each write. So basically <strong>'FileLock'</strong> is a way to ensure to get exclusive lock on the File. But since it is XML, I tried to load using <strong>JAXB</strong>.</em> </p>
  
  <pre><code>JAXBContext context = JAXBContext.newInstance(rootClass);
  Unmarshaller um = context.createUnmarshaller();
  Object obj = um.unmarshal(new FileInputStream(sourceXml));
  </code></pre>
  
  <p>with <strong>JAXB</strong>, for once I have to read the file using FileInputStream and get exclusive lock on the channel. </p>
  
  <pre><code>JAXBContext context = JAXBContext.newInstance(rootClass);
  Marshaller m = context.createMarshaller();      
  m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
  m.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
  m.marshal(rootObj, xmlFile);    
  </code></pre>
  
  <p>But later to write it, the file is already locked by InputStream.</p>
  
  <p>RandomAccessFile to simultaneously read/write is not an option for the XML file.</p>
  
  <p>any ideas to get around this with single lock mechanism?</p>