p2p.wrox.com Forums

Need to download code?

View our list of code downloads.

  Return to Index  

java_howto thread: scheduling a java class to run every day

Message #1 by "Bruce Altner" <baltner@h...> on Tue, 20 Mar 2001 18:19:40
One solution would be to create a Scheduler class.  This class would 
contain some collection of tasks.  Each task would have its own field(s) 
telling when it is to be run.

As part of its construction, this Scheduler class should start a thread.  
The thread's run() method would contain an infinite loop that sleeps for 
some interval (say, 30 seconds, depending on your needs).  Each time it 
wakes from its sleep, it could get the current date and time from the 
system clock, then check to see what activities (if any) are scheduled for 
that particular time.

Each task has information telling when it is to be run.  Depending on how 
you implement this, you could provide absolute times (e.g., next Monday at 
noon), repeating times (e.g., every night at 11:00 p.m.), or a recurring 
basis (e.g., every 10 minutes).

  Return to Index