The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

Java filesystem hooks/interrupts.

I hate to ask this here, but the Java forums are a cluttered mess of freshmen asking for homework help.

Very simply: There are two ways to monitor a file system for changes. One is to poll it at intervals looking for modification-date changes. This is obviously inefficient, especially if you're dealing with millions of files. The other way is to simply ask the OS, "Notify me on changes" and wait for said notifications.

For the life of me, I can't find a definitive statement on whether the latter is possible in 100% pure Java--or, if not possible, how exactly it can be done through JNI.

Any help?
Not a guru
Thursday, June 14, 2007
 
 
In the same boat here. Hundreds, maybe thousands of XML files that need to be monitored until we get them into a database. Which will probably not help with making monitoring easier.

This article on Artima:

http://www.artima.com/lejava/articles/more_new_io.html

makes it sound that file change notification is being considered for one of the next versions of Java. So it sounds like we're currently stuck with polling in "pure" Java.
Cow Orker Send private email
Thursday, June 14, 2007
 
 
There's a nifty library that makes polling a snap:

http://jpoller.sourceforge.net/
Chris Winters Send private email
Thursday, June 14, 2007
 
 
Sounds like a case for JNI, especially if the number of files is large and you want to minimize overhead.

For example, Linux has inotify, and I believe kevent can handle this on the BSDs.  Fallback to a pure java poller if on a platform without a native library to handle this.
nimrod Send private email
Thursday, June 14, 2007
 
 
I believe there is an Apache Commons file monitoring utility to handle this situation.
Benjamin Manes Send private email
Thursday, June 14, 2007
 
 
Not a guru
Thursday, June 14, 2007
 
 
Short answer = Java does not support this as yet (97% sure).

Java cannot 'really' support asynch notifications in the API until all OSs that JVMs run on support it. Win32 API supports asynch callbacks (I have used them) but Unixes don't (as of 2002-3, when I investigated the issue). Any jakarta library other posters mentioned probably polls under the hood on *nix OS.

That being said, if java 7 has an API which polls under the hood, do you mind all that much ?

If *nix supports asynch notifications now, then u can write JNI code to do on Win32 and *nix yourself.
Serge Merzliakov Send private email
Thursday, July 05, 2007
 
 
http://jnotify.sourceforge.net/

for windows and linux

give it a try — it's better that polling
Stan Klimoff Send private email
Tuesday, July 10, 2007
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz