If there are any other solution which you feel better, you can tell me.
Santhosh Venkatesan wrote:I don want to restrict with any OS as i always wanted to be Platform independent.
Then you're out of luck, because this probably isn't just OS dependent - it's probably file system dependent. NTFS may support it, whereas FAT32 may not (to be honest, I have no idea). Either way, you will need to use JNI for this.
Mike Simmons wrote:Something like this is supposed to be available in JDK 7
That's actually pretty cool, but it still uses polling if the file system does not support notifications.
Adam Michalik wrote:You may also wish to have a look at Apache Commons VFS - I found that it supports something called FileChangeEvent with ChangedEvent, CreateEvent and DeleteEvent as subclasses - seems like it's what you need. Though I haven't used it myself
That one also polls, something Santhosh is trying to avoid.
So the end conclusion is: it's possible for some file systems in native code, for others you need to poll.
The point is, it consumed very little of the system resources. Barely a few percents, and most of that was probably due to running the code that got triggered.
So, my question here is... is it really an issue? Is your current code, very inefficient?
see API docs for FileSystem,FileRef,Watchable,WatchEvent and WatchService classes.
Also you might take a look at a sample i posted some time ago.
Rob: yeah, it may revert to polling if there's no alternative, but that's the best you can do in the face of an impossible requirement, I think. It uses the OS facilities if they're available.
Henry's point is also good - in general, polling really isn't a problem. Unless perhaps you need to react to file changes within a few milliseconds, or unless you have a directory with a huge number of old entries that you have to filter out while looking only for the new ones. In the latter case, you probably need to modify the process to delete or move the already-processed files, so they don't gum up the works.
Mike Simmons wrote:Really, they have that in JDK 7? I had no idea..
you are in the wrong business,you should be a comedian,such funny jokes,ohhh I am dying of laughter