I have a set of files. The set of files is read-only from the NTFS share, so there can be many readers. Each file is periodically updated by one author who has write access.
How to ensure that:
- If the write failed, the previous file is still readable.
- Readers Cannot Delay Single Writer
I am using Java, and my current solution is for the writer to write to a temporary file and then replace it with the existing file with File.renameTo()
. The problem is NTFS, it renameTo
fails if the target file already exists, so you need to delete it yourself. But if the author deletes the target file and then fails (computer crash), I don't have a readable file.
nio FileLock only works with one JVM, so it is useless to me.
How to safely update a file with many readers using Java?
source
share