I am using WatchService of NIO. Two classes to watch a specific directory (Ubuntu 11.10).
Whenever a change is made, for example if I modify a existing file, it fires a MODIFIED event 2 times. Don't know why? It works fine when I create new file.
I found a solution for it. It fires two modify events, because when the filesystem writes new files, it creates it with zero byte and fires create event and then it writes data to the and file then it fires the modify event.
The same applies with modifications. When we modify an already existing file, the filesystem first creates it with 0 bytes and fires a modify event and then writes data to it. Then it fires the modify event again. That's why I was receiving two modify events.
I've used example from Oracle, and strangely sometimes it fires ENTRY_MODIFY twice and sometimes it fires it once. I am using Windows machine.
In the docs there is no info about possible duplicated events, so I guess it is either an undocumented behavior or a bug.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With