I'm working on a program in Java where a read/write lock is required. The scenario is multiple processes can write to the file at the same time. I have used the following line to lock the File.
FileOutputStream fos = new FileOutputStream(file);
FileLock lock = fos.getChannel().lock;
This works fine when multiple processes try to write to the file simultaneously. The other processes are waiting till the lock is released. However, the other processes are still able to read this file and when they open the InputStreamReader to read this file, the initial process which is writing to this file stops and the read process starts. I want the read process also to be synchronized.
Can someone help me with this. (This runs on multiple processes and also threads)