哪些操作系统支持在 Java 中查看本机(类似 inotify)文件 [英] Which Operating Systems support native (inotify-like) file watching in Java

查看:19
本文介绍了哪些操作系统支持在 Java 中查看本机(类似 inotify)文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

java.nio.file.WatchService 的 JavaDoc 状态;

The JavaDoc for java.nio.file.WatchService states;

实现...是旨在直接映射到 本地文件事件通知设施(如果可用),或使用原始机制,例如轮询,当本地设施不可用时.

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

对于窗户:

/*
 * 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/

由于操作系统实际支持此功能,因此您似乎需要查看实际发行版.

As what OS actually supports this, it seems like that would require for you to look at the actual distro.

这篇关于哪些操作系统支持在 Java 中查看本机(类似 inotify)文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆