3 ms·
Another new feature in Java 7 is the WatchService API[1], which allows one to watch a directory for file changes (implemented using native filesystem methods).
by waffle_ss 15y ago
Another new feature in Java 7 is the WatchService API[1], which allows one to watch a directory for file changes (implemented using native filesystem methods). Previously, this could only be done with polling[2] or custom native code called through JNI.
[1]: http://docs.oracle.com/javase/tutorial/essential/io/notification.html http://docs.oracle.com/javase/tutorial/essential/io/notifica...
[2]: http://jnotify.sourceforge.net/ http://jnotify.sourceforge.net/
- bwarp 15y agoThat is one thing I've been wanting for years. Thanks for pointing it out.
- moonchrome 15y agoHow is Java7 API not using polling ? You create a watch service and then you call poll on it to get update events - or am I missing something ?
- arethuza 15y agoDo you mean pooling or polling?
- moonchrome 15y agoMy error - corrected (intellisense keeps you ignorant about these errors/english isn't my first language so it doesn't sound strange :))
- waffle_ss 15y agoIt only falls back to polling if there is no support for using the native filesystem method. You don't have to use `poll()`, you can use `take()` which is the blocking equivalent to it. In fact, in most use cases I would imagine you would spawn a thread and use `take()`. I'm guessing they called it `poll()` as it is non-blocking, so if you don't get a result then you have to keep calling it. However, I don't think it reflects the implementation details. Here's the JavaDoc for more info (guess I should have linked to it originally): http://docs.oracle.com/javase/7/docs/api/java/nio/file/WatchService.html http://docs.oracle.com/javase/7/docs/api/java/nio/file/Watch...