private void writeJobSuiteIndex(JobSuiteStatusSnapshot statusTree) throws IOException { File indexFile = getSuiteIndexFile(); StringWriter out = new StringWriter(); out.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"); out.write("<suite-index>"); //--- Log Manager --- out.flush(); getLogManager().saveToXML(out); //--- JobStatusSerializer --- out.flush(); getJobStatusStore().saveToXML(out); //--- Job Status --- writeJobId(out, statusTree, statusTree.getRoot()); out.write("</suite-index>"); out.flush(); // Using RandomAccessFile since evidence has shown it is better at // dealing with files/locks in a way that cause less/no errors. try (RandomAccessFile ras = new RandomAccessFile(indexFile, "rwd"); FileChannel channel = ras.getChannel(); FileLock lock = channel.lock()) { ras.writeUTF(out.toString()); } }