哪些操作系统支持在Java中查看本机(类似inotify)文件 [英] Which Operating Systems support native (inotify-like) file watching in Java
问题描述
JavaDoc for java.nio.file.WatchService
states;
The JavaDoc for java.nio.file.WatchService
states;
实现...是
,用于直接映射到本机文件事件通知
facility (如果可用),或者使用原始机制,例如
polling ,当本地设施不可用时。
The implementation ... is intended to map directly on to the native file event notification facility where available, or to use a primitive mechanism, such as polling, when a native facility is not available.
我认为这意味着它会尝试一种轻量级的本机机制(如果可以的话)如果不能在Linux上 inotify
并进行轮询,如果不能。
I assume this means it will try a lightweight, native mechanism when it can (something like inotify
on Linux) and poll if it can not.
这是正确的吗?
哪些操作系统可能或不可能提供此类设施? Linux的发行版级别真的很有用,或者我可以假设如果JVM在* unix上运行,它将受支持吗?
What operating systems are likely or unlikely to provide such a facility? Distro level for Linux would be really useful or can I assume that if the JVM runs on *unix, it will be supported?
推荐答案
这应该是一个评论,但它太大了,不能发布它......
This should have probably been a comment, but it's too big to post it as such...
我在看 jdk-9
来源(也可以在jdk-8回购中轻松搜索),但这里有一些与你的问题评论有关:
I am looking at jdk-9
sources (could easily be searched in the jdk-8 repo as well), but here is some relevant to your question 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
对于windows :
And for windows:
/*
* Win32 implementation of WatchService based on ReadDirectoryChangesW.
*/
class WindowsWatchService extends AbstractWatchService
依此类推..你可以找到所有可用的实现:
And so on.. you can find all the available implementations under:
jdk/src/java.base/{windows|unix|solaris|linux...}/classes/sun/nio/fs/
正如OS实际支持的那样,看起来这需要你看看实际的发行版。
As what OS actually supports this, it seems like that would require for you to look at the actual distro.
这篇关于哪些操作系统支持在Java中查看本机(类似inotify)文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!