wolfgang.baltes wolfgang.baltes at
Wed Dec 15 15:19:00 PST 2010


I have started to use the WatchService and would like to get confirmation for some of my observations. At least one of them is not in agreement with the documentation.

My system is Windows 7 Ultimate 64bit with JDK7-b121 32bit and using Eclipse 3.61 32bit as the development platform. I am writing a piece of code that watches one or several directories recursively or not for file additions and deletions.

My observations are for a directory tree where all directories/subdirectories are being watched. I use Windows Explorer to copy files and directory trees into this directory tree and to delete them.

1 - If I delete a file at any level in the tree, then I get the ENTRY_DELETE event for the file and an ENTRY_MODIFIED event for its parent directory. - This should be normal.

2 - If I delete a subdirectory that contains files but no further subdirectories, then I receive an ENTRY_DELETE event for the subdirectory and an ENTRY_MODIFIED event for its parent directory. In addition - and only sometimes - I also receieve ENTRY_DELETE events for the files within the subdirectory. - I assume that this is normal, although I don't understand the random behavior of getting or not getting events regarding the files.

3 - If I try to delete a subdirectory tree - that is a subdirectory with nested directories - then Windows Explorer does not let me delete the tree. The WatchService seems to block this. I can however, delete this tree by starting at the bottom (leaf) directories and delete them one at a time. This corresponds essentially to the scenario described in 2. - This may be normal, but is certainly not convenient. Is this a Windows feature?

4 - Contrary to the documentation (tutorial on WatchService), the WatchKey remains valid (isValid()) after deletion of the associated directory. That is, the expression (dir.notExists() && key.isValid()), where key is the WatchKey associated with dir is true. The first part of the expression confirms that dir is deleted, and the second part should be false if the key is automatically cancelled. - I don' think this is normal at all!

Thanks for any comments you may have,

Une messagerie gratuite, garantie à vie et des services en plus, ça vous tente ?
Je crée ma boîte mail
-------------- next part --------------
An HTML attachment was scrubbed...

More information about the nio-dev mailing list