Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Background App

Reply
Thread Tools

Background App

 
 
Andrew Tucker
Guest
Posts: n/a
 
      07-31-2003
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!

cheers, Andrew.


 
Reply With Quote
 
 
 
 
Andy Fish
Guest
Posts: n/a
 
      07-31-2003
AFAIK there is no way to receive a notification when a file is changed. For
windows you could do this using JNI but it would be platform specific.

If you need to go the polling route use Thread.sleep() to pause the program

Andy

"Andrew Tucker" <(E-Mail Removed)> wrote in message
news:3f28cd11$(E-Mail Removed)...
> 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!
>
> cheers, Andrew.
>
>



 
Reply With Quote
 
 
 
 
Brad BARCLAY
Guest
Posts: n/a
 
      07-31-2003
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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DIV background-repeat background-image? For shadow effect jc ASP .Net 3 03-19-2008 04:19 PM
DIV background-repeat background-image for shadowing effect jc HTML 1 03-19-2008 02:16 PM
not able to click on background tab and backgrounds in properties to change the background. rex Computer Support 2 12-06-2006 02:26 AM
Background transparent when 'background' is used JWL HTML 4 09-26-2006 05:37 PM
Background Check - Background search - People search mason66 ASP .Net 0 07-27-2006 10:20 AM



Advertisments