How to safely update a file that has many readers and one writer?

I have a set of files. The set of files is read-only off a NTFS share, thus can have many readers. Each file is updated occasionally by one writer that has write access. How do I ensure that: 1. If the write fails, that the previous file is still readable 2. Readers cannot hold up the single writer I am using Java and my current solution is for the writer to write to a temporary file, then swap it out with the existing file using `File.renameTo()`. The problem is on NTFS, `renameTo` fails if target file already exists, so you have to delete it yourself. But if the writer deletes the target file and then fails (computer crash), I don't have a readable file. nio's FileLock only work with the same JVM, so it useless to me. How do I safely update a file with many readers using Java?

以上就是How to safely update a file that has many readers and one writer?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏