WatchService unreliable on Linux

I tried a simple WatchService application in Java 7. It looks at the directory for new files. It runs on Linux CentOS 6. I can copy the file to the watched directory, and I get a file creation event. Things are good.

I was based on this Oracle example.

The problem is that the key is invalid inexplicably. Javadoc says there are several cases that can cause this, such as a key cancellation. I do not cancel it. This is not valid when the program runs without creating a file. Just sat there and it is not valid in minutes or longer. Once he escaped for four days before mysteriously went void.

The only possible explanation for Javadoc is that the browsing directory has been deleted or is no longer available. Of course, I do not delete it. This leaves availability.

Now I am wondering if the WatchService Linux implementation uses the fact that the directory is unavailable due to system loading or something else. I can’t imagine what it would do. The system is not loaded. The file system containing the directory is local to this system. This directory is not used by anything else.

What are some other features?

+4
source share

Source: https://habr.com/ru/post/1479970/


All Articles