Process-A writes bytes to a data-file using FileOutputStream. Process-B reads from the same data-file using DataInputStream.
The data-file resides on a NFS mount that doesn't support FileLocks so following approach is used:
Process-A creates a lock file to inform Process-B that it can start reading the data file. It creates the lock file after it flushes and closes the FileOutputStream. Process-B checks if the lock file exists and then starts reading the data-file. However, sometimes it encounters EOFException.
java.io.EOFException
at java.io.DataInputStream.readFully(DataInputStream.java:180)
at java.io.DataInputStream.readUTF(DataInputStream.java:592)
at java.io.DataInputStream.readUTF(DataInputStream.java:547)
java.io.EOFException
at java.io.DataInputStream.readInt(DataInputStream.java:375)
at java.io.DataInputStream.readFloat(DataInputStream.java:429)
Can someone explain, what is going wrong? Also, is there any other alternative approach given that i can't use FileLock api?
Nothing is going wrong. You have reached the end of the stream. The peer has closed his end of the connection. Close your end and forget about it.