JDK 7 WatchService API and NFS file sharing
Asked Answered
D

1

6

We are using [WatchService][1] API (JDK 7) to track files created in my system. And up till now, it worked ok. Every file created on my system tracked by my program.

But we have trouble when we use NFS (the directory we track actually exist on another computer in LAN).

WatchService does not work.

Can anyone tell me how to work around this situation? How can I setup NFS to support Java 7 WatchService API or can anyone tell me a better library.

Thanks all

Dildo answered 24/7, 2012 at 10:7 Comment(3)
NFS is actually very problematic. Same applies to Lucene indexes on NFS mounts. You are probably out of luck here.Pannier
The underlying file system doesn't support it. https://mcmap.net/q/278494/-inotify-with-nfs Is there a way to force the Watch Service to fall back to polling for changes?Greenockite
My advice to you is never to design or write an application that relies on shared file systems. These are for users, not code. There is just too much to deal with in the way of failure modes, and as @Pannier says, NFS is one of the most problematic of them.Inconsolable
C
2

You can mix your code with Polling Watcher from OpenJDK (Polish text)

Sources

Capitalization answered 10/12, 2012 at 16:44 Comment(2)
Hack is real :)Selfexecuting
Creating classes under openjdk.sun.nio.fs package is not advised.Spiritualism

© 2022 - 2024 — McMap. All rights reserved.