简体   繁体   中英

Java7: Detect all files when creating a new non-empty directory

I'm implementing a WatchDog to look recursively for file changing, deleting and adding in a directory, I'm using linux. The program works well and doing it with Java7 is pretty straightforward, the only thing is that when I add a directory with some files in it I'm not able to monitor the adding of all the contained files. I think the problem is that when I'm adding a new directory, WatchDog has to register it to the WatchService and in the meantime some file added are lost (usually one or two). WatchDog is a Thread that puts every updateEvent in a blockingQueue that is read by another Thread.

Here's th WatchDog: http://pastebin.com/q5SW0iJF

Has anyone experienced the same problem and if yes, how did you solve that?

Thanks

Perhaps you should consider the Java 7 WatchService API ? It'll save you reinventing the wheel.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM