Andrew Tucker wrote:
> I have written a small program to monitor a given file and when that file is
> modifed, to back it up (Like a mirror idea). The program consists of an if
> statement w/in a while(true), ie it loops forever, this is chewing up my cpu
> with constant 'activity', is there an easier way to do this, would i be
> better to just compare every couple of minutes or is there a way of making
> things run in the background and only react when the file is changed. I
> haven't explained this very well but i hope someone can point me in the
> right direction!
Most OS's don't have any sort of subsystem that will allow the
filesystem to report whenever a specific file has been changed, so there
isn'treally any better way to do this in Java other than to poll.
However, you shouldn't poll in a busy-loop without adding some wait
time. It doesn't have to be very long -- even a 5 second wait will
cause a huge performance increase. Find the point where you want to
pause for a short period of time, and add the code:
try {
synchronized(this) {
wait(5000l);
}
} catch (InterruptedException e) {
// Who cares?

}
This should fix your problem. HTH!
Brad BARCLAY
--
=-=-=-=-=-=-=-=-=
From the OS/2 WARP v4.5 Desktop of Brad BARCLAY.
The jSyncManager Project:
http://www.jsyncmanager.org