Is Java 7 WatchService Slow for Anyone Else?

后端 未结 2 1846
后悔当初
后悔当初 2020-12-01 05:18

WatchService looks like a great technology but its been too slow to be useful on the OS X and Linux systems I\'ve tested on. To add insult to injury, it doesn\'t seem to ge

相关标签:
2条回答
  • 2020-12-01 05:28

    I have much better response times if I change

    folder.register(watcher, StandardWatchEventKinds.ENTRY_MODIFY);
    

    to

    folder.register(watcher, new WatchEvent.Kind[]{StandardWatchEventKinds.ENTRY_MODIFY}, SensitivityWatchEventModifier.HIGH);
    
    0 讨论(0)
  • 2020-12-01 05:30

    JDK 7 does not yet have a native implementation of WatchService for MacOS. Rather than listening for native file system events, it uses the fallback sun.nio.fs.PollingWatchService, which periodically traverses the file system and checks the last modified timestamp of each file and subdirectory in the tree. I've also found it to be unusably slow.

    There is a native implementation of WatchService for Mac:

    http://code.google.com/p/barbarywatchservice/

    I haven't tried to use it myself.

    0 讨论(0)
提交回复
热议问题