javapollingwatchservicejnotify

JNotify vs Polling


I am working with Java 6 and can not use Watch Service. I am looking for an alternative to polling. So how is JNotify different from polling? Or does JNotify uses polling?


Solution

  • JNotify is using the native OS support for file system notifications. on Linux it's using INotify (which is the inspiration for it's name), on Windows it's using ReadDirectoryChangesW and on Mac it's using FSEventStream API. I started JNotify around 2005, long before the JVM supported file system notifications. Today the recommended way is to use the JVM support, but if you can't rely on that is a good alternative.

    One thing to remember is that JNotify is using the OS support which is sometimes no great. in some cases file system events gets dropped by the OS and there is not much you can do about it.