Wolfgang Baltes wolfgang.baltes at
Mon Jan 17 15:54:58 PST 2011

On 2011-01-12 02:43, Alan Bateman wrote:
> Wolfgang Baltes wrote:
>> There are several observations to be made:
>> - The rmdir command iterates from the bottom of the tree up.
>> - Sometimes, the deletion of file3 is reported after its directory 
>> subsubdir is effectively deleted.
>> - Most of the time, the deletion of file4 is not reported, probably 
>> because the watch key is canceled.
>> - The parent of the watched directory subsubdir is not deleted 
>> (directory subdir remains after the code has finished). This is the 
>> bug you mentioned in an earlier message.
> Yes, it's because there is an open handle to each directory that you 
> register with the WatchService. It doesn't prevent the directory from 
> being deleted but we need the notification to trigger the closing of 
> the handle and so there is a tiny window where it is possible to 
> delete the parent directory after deleting the sub-directory. We have 
> in the bug database but I don't think we can do anything about it.
> One thing I should have mentioned before is that our Windows 
> WatchService implementation supports an implementation specific 
> modifier that allows you to monitor a file tree with a single 
> registration. If you want to try it out do this:
> register(watcher,
>             new WatchEvent.Kind<?>[]{ ENTRY_DELETE },
>             com.sun.nio.file.ExtendedWatchEventModifier.FILE_TREE);
> With this modifier then you only register the top directory and the 
> context for each event is the relative path from the top directory. 
> It's not a portable solution and only works on Windows but it would be 
> interesting to how it compares.
Hi Alan,

thanks again for this tip. I modified the WatchDir program to use the 
suggested Windows-specific registration. This works as expected: when 
deleting a file tree using Windows Explorer, then I only get an event 
for the directory being removed (no event for any file or subdirectory 
contained therein). When using rmdir from the command prompt, then I get 
events for each item.

When adding/creating a subtree, then I get events for all items.

Will this modifier remain in the final version of JDK7, or is it only 
experimental and may get removed?


More information about the nio-dev mailing list