How to check if file is completely written / holds a write lock with only read access in Java

huangapple 未分类评论53阅读模式
英文:

How to check if file is completely written / holds a write lock with only read access in Java

问题

我有一个进程在系统中写入文件。现在我想在Java中检查文件是否已完全写入(即不存在写入锁定)。然而,我只对该文件具有读取访问权限!

据我理解,由于我只有读取权限,所以不可能尝试独占锁定。我也不想让线程休眠并检查文件大小的更改,因为这样做太慢了。我无法更改关于写入文件的进程的任何内容。该文件必须保持原地不动。

是否有任何可行的想法?

英文:

I have a process writing a file to the system. Now I want to check in Java if the file is fully written (i.e. no write lock exists). However, I only have read access to this file!

As far as I understand it is not possible to try an exclusive lock, because I only have read permissions. I also don't want to sleep the Thread and check for changes of the file size because this is too slow. I cannot change anything about the process writing the file. The file has to remain in-place.

Any viable idea?

huangapple
  • 本文由 发表于 2020年4月11日 02:12:05
  • 转载请务必保留本文链接:https://java.coder-hub.com/61146186.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定