0

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?

p192
  • 518
  • 1
  • 6
  • 19
  • JNotify is a java-wrapped API of linnotify, which is originally for linux. It does not use direct polling to the directory. The OS will notify the change of the directory, and JNotify listens to it. But do you have any reason to use Java 6? – jungyh0218 Aug 11 '15 at 00:51
  • Yes. It is required that I use Java 6. And your answer helped me clarify my doubts. Thank you. – p192 Aug 11 '15 at 01:30

1 Answers1

0

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.

Omry Yadan
  • 31,280
  • 18
  • 64
  • 87
  • Btw, do you know if Apache Commons IO File Monitor (https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/monitor/package-summary.html) uses polling or not? It seems like it doesn't but I've been reading in other places that it does use polling. – p192 Aug 12 '15 at 21:48
  • I am not familiar with that project. – Omry Yadan Aug 13 '15 at 00:52