MacOS上Java目录WatchService的状态

问题描述 投票:-1回答:1

[MacOS的Java平台上WatchService的状态是什么?

似乎没有在7和8上进行过工作。

在更高版本中已解决?我们现在13岁了。

java macos
1个回答
0
投票

据我所知,它可以在带有OpenJDK 8的MacOS上运行。

/tmp$ java DirectoryWatcherExample                        
Event kind:ENTRY_CREATE. File affected: test.txt.                               
Event kind:ENTRY_DELETE. File affected: test.txt.                               
Event kind:ENTRY_CREATE. File affected: test.txt.                               
Event kind:ENTRY_MODIFY. File affected: test.txt.                               
Event kind:ENTRY_DELETE. File affected: test.txt.                               

/tmp$ java -version                                     
openjdk version "1.8.0_232"                                                     
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_232-b09)                 
OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.232-b09, mixed mode)          

/tmp$ uname -v                                            
Darwin Kernel Version 18.7.0: Sat Oct 12 00:02:19 PDT 2019; root:xnu-4903.278.12
~1/RELEASE_X86_64

您可以尝试输入代码DirectoryWatcherExample.java

原始来源:A guide to WatchService in Java NIO2

JDK似乎已经实现了称为kevent的机制,这是基于OpenBSD / solaris的系统的通知机制。我没有搜索汞库的经验,因此,我能找到的最好的是一个只读的JDK8源代码,它显示了kqueue的实现。

© www.soinside.com 2019 - 2024. All rights reserved.