Java 7 directory monitoring issues

I just saw an awesome function with java 7, the directory watcher. It will tell you when something has changed in the directory without polling the directory.

1.) But he says that he returns to the survey if the file system does not support the recording of change events. Are all standard linux and windows file systems supported (extX, ntfs, reiserXXX, jsf, zfs)?

2.) Does the file inside the directory rename the create or change event? Or is it one to delete and one to create? I can test it on one system, but will it be the same for all file systems?

+7
source share
2 answers

It looks like you're talking about WatchService .

The ENTRY_CREATE statement says that a new record will be accepted if a new file is created or the file is renamed to a directory. It lacks a specification of which events are fired if the file is renamed and remains in the same directory.

The wording also indicates whether the execution of the service depends on the operating system or the polling. I suspect that the JRE implementation, therefore, even if you know that a particular OS supports it, this is not a guarantee that the service will use functionality at the OS level or resort to a survey. In fact, the service does not provide any way to determine if it is using a polling or OS level function.

The operations defined by the API also do not behave like a Listener. WatchService does an automatic review, but to get a list of events that occur, you still have to manually request the events you see from the service. It does not seem to provide any hooks to automatically call when a new event is present.

+2
source

If you play with it on Windows and Linux, you will see many differences in behavior. Thus, Java is not really trying to provide a consistent platform-independent abstraction. You must test your application on the OS you care about (well, there are only 2 of them).

WatchService sucks more than you can imagine. Get ready for disappointment if you really immerse yourself in it.

+1
source

All Articles