JAVA实现inotify一样的功能_哪些操作系统支持在Java中查看本机(类似inotify)文件
JavaDoc for java.nio.file.WatchService狀態;
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),如果不能,則進行輪詢.
那是對的嗎?
哪些操作系統可能或不可能提供這樣的設施? Linux的發行版級別真的很有用,或者我可以假設如果JVM在* unix上運行,它會受到支持嗎?
解決方法:
這應該是一個評論,但它太大了,不能發布它…
我正在查看jdk-9源代碼(也可以在jdk-8 repo中輕松搜索),但這里有一些與你的問題評論有關:
/**
* 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:
/*
* Win32 implementation of WatchService based on ReadDirectoryChangesW.
*/
class WindowsWatchService extends AbstractWatchService
等等..您可以在以下位置找到所有可用的實現:
jdk/src/java.base/{windows|unix|solaris|linux...}/classes/sun/nio/fs/
正如操作系統實際上支持這一點,似乎需要您查看實際的發行版.
標簽:java,linux,java-8,raspberry-pi,inotify
來源: https://codeday.me/bug/20190527/1164337.html
總結
以上是生活随笔為你收集整理的JAVA实现inotify一样的功能_哪些操作系统支持在Java中查看本机(类似inotify)文件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java怎么测试dao_java-Moc
- 下一篇: php扩展-ioncube组件的安装方法