英文:
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?
专注分享java语言的经验与见解,让所有开发者获益!
评论