Which operating systems support native (inotify-like) file viewed in Java
The JavaDoc states for java.nio.file.WatchService
:
The implementation ... is intended to bind directly to the event notification object where possible, or to use a primitive mechanism like polling when the native object is not available.
I guess this means that it will try a lightweight, proprietary mechanism when possible (sort of like inotify
on Linux) and poll if it cannot.
Is it correct?
Which operating systems are likely or unlikely to provide such a facility? Would a Distro layer for Linux be really helpful or can I assume if the JVM runs on * unix it will be supported?
source to share
It may have been a comment, but too long to post as such ...
I look at the sources jdk-9
(can be found easily in the jdk-8 repository), but here are some of them pertaining to your comments:
/**
* Linux implementation of WatchService based on inotify.
*
* In summary a background thread polls inotify plus a socket used for the wakeup
* mechanism. Requests to add or remove a watch, or close the watch service,
* cause the thread to wakeup and process the request. Events are processed
* by the thread which causes it to signal/queue the corresponding watch keys.
*/
class LinuxWatchService extends AbstractWatchService
And for windows:
/*
* Win32 implementation of WatchService based on ReadDirectoryChangesW.
*/
class WindowsWatchService extends AbstractWatchService
And so on .. you can find all available implementations under:
jdk/src/java.base/{windows|unix|solaris|linux...}/classes/sun/nio/fs/
As the OS actually supports it, it looks like you will need to look at a real distribution.
source to share
I think you can find some information in this post Watchservice is not working on Windows 7 . There is a note on file system watchers on Windows and MacOSX (the author of the post says they use polling). Linux filesystem monitoring is part of the Linux kernel and implemented using a pretty nice notification mechanism (more information on some of them can be found here )
source to share