I have java process 1 which uses rpc to call java process 2 which creates a file on a mapped network drive. Process 1 then attempts to read the file. Usually the file is read ok but sometimes it can't find the file even though I can see that it does get created.
Process 1, 2 and the mapped drive are each on separate Windows Server 2008 machines. Therefore the processes are on separate JVMs and separate operating systems.
Process 2 does this sort of thing before returning (meaning that it ensures the file is written to disk before returning from the rpc call):
FileOutputStream fileOut = new FileOutputStream(new File(pdfPath));
bufferedOut = new BufferedOutputStream(fileOut);
// write to file
bufferedOut.flush();
fileOut.getFD().sync();
bufferedOut.close();
Process 1 will attempt to read the file after the rpc method call returns.
I'm sure that the file is written before process 1 attempts to read it but that some caching is taking place in either the JVM or the operating system which is preventing the process from detecting the file
There's no error until I try to read the file and it looks like this:
java.io.IOException: G:/mydir/my file ( 1.pdf not found as file or resource.
at com.itextpdf.text.pdf.RandomAccessFileOrArray.<init>(RandomAccessFileOrArray.java:113)
at com.itextpdf.text.pdf.RandomAccessFileOrArray.<init>(RandomAccessFileOrArray.java:80)
at com.itextpdf.text.pdf.PRTokeniser.<init>(PRTokeniser.java:112)
at com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:169)
at com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:159)
...