WatchService re-register events appended or replaced

Michael Hall mik3hall at
Thu Jul 26 03:05:23 PDT 2012

On Jul 25, 2012, at 11:11 PM, Alan Bateman wrote:

> On 26/07/2012 00:13, Michael Hall wrote:
>> This isn't clear to me from the javadoc which I thought might make it worth raising the question even if I could track down the answer myself.
>> When you re-register a path you should get the same WatchKey back. Does it keep it's old events and get the new ones added?
>> I assume re-register amounts to an event reset but would feel safer in this assumption with some confirmation?
> I think this is all covered in the javadoc (register method):
> "If the file system object identified by this object is currently registered with the watch service then the watch key, representing that registration, is returned after changing the event set or modifiers to those specified by the events and modifiers parameters. Changing the event set does not cause pending events for the object to be discarded. "
> So calling register on an object that is already registered does change the event set but it doesn't discard events that are waiting to be retrieved. Hopefully this helps.
> -Alan

That does clear it up. It took a little while while to find it though. It is not mentioned in the WatchService or Path javadoc but the Watchable.

It was about the only way the test/java/nio/file/WatchService/Basic testEvents() method was going to run. Which I guess makes that a good test.

-------------- next part --------------
An HTML attachment was scrubbed...

More information about the nio-dev mailing list