Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
689 views
in Technique[技术] by (71.8m points)

file - Java WatchService not generating events while watching mapped drives

I implemented a file watcher but I noticed that java nio file watcher doesn't generate events for files being copied on mapped drives. For instance, I've run the file watcher on Unix to watch a local directory (/sharedfolder) which is mapped on windows (H:), and then I've put a file in this directory (H:) but the file watcher hasn't generated any event. Now if I run the file watcher on windows to watcher the mapped drive (H:) which refers to a unix path (/sharedfolder) and from unix I put a file in this folder, the file watcher identifies the change and generates an event. It looks like a bug, or may be I'm missing some thing, any thoughts?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I have the same issue trying to watch a mounted windows share via CIFS. It seems not possible to get filesystem events for CIFS mounts.

The linux implementation of the Java 7 NIO FileWatcher uses inotify. Inotify is a linux kernel subsystem to notice filesystem changes which works perfect for local directories, but apparently not for CIFS mounts.

At Oracle, it doesn't seem to be high priority to fix this bug. (Is it their responsibility? More of an OS issue...)

JNotify also uses inotify on linux systems, so this is no option either.

So mapped drives monitoring unfortunately seems to be limited to pollers:

  • Apache VFS DefaultFileMonitor to poll directories (mounted share)
  • File Poller based on the standard Java API.
  • Custom File Poller with jCIFS (so the share doesn't need to be mounted on the host)

I'll probably try the Apache VFS Monitor, because it detects file creation, updates and deletes out of the box. It requires to mount the share, but that gives the OS the responsibility of CIFS connections and not my application.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...