I want to use the Java WatchService
to listen for changes on a big number of directories (many hundreds of thousands) but I don't know if it is appropriate for such numbers of watched directories.
Does anyone have experience with WatchService
with such numbers of directories?
If it helps, the WatchService
will be used on CentOS 6.5 with an EXT4 file system.
Thanks, Mickael
This situation is fairly common for IDEs. They often use directory watching for complex directory structures and many 10s of thousands of files.
There is two things to note:
To prevent this situation it is recommended to increase the watches limit (to, say, 512K). You can do it by adding following line to the /etc/sysctl.conf file:
fs.inotify.max_user_watches = 524288
This example tunes the system to monitor 512k files.
Like many IO operations in Java, it is wrapper around a facility which is actually implemented by the OS.
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