i have a scheduled task that runs every 5 mins, if everything went ok.
if the last execution of this scheduled task returned false, the delay
should be 10 mins.
how do i do this?
here's a code sample (using 5-minute [fixed-rate] delays):
java.util.Timer myTimer = new java.util.Timer();
myTimer.schedule(new MyRunner(), 0, 300000);
...
static class MyRunner extends TimerTask {
public void run() {
FileOpenTask myTask= new FileOpenTask();
myTask.openFile("myFile.txt");
}
}
....
public class FileOpenTask {
// the returned value of this method is, at this point, useless to
the caller
public boolean openFile(String filename) {
try {
FileInputStream fstream = new FileInputStream(filename);
} catch (FileNotFoundException fnfe) {
return false;
}
return true;
}
}
Oliver Wong - 06 Jul 2006 16:35 GMT
>i have a scheduled task that runs every 5 mins, if everything went ok.
> if the last execution of this scheduled task returned false, the delay
> should be 10 mins.
> how do i do this?
How about having the task take care of scheduling its next invocation?
So when you first want to run the task, you tell it to run right now,
without any timer stuff. The tasks runs, doing its main work. Once the main
work is done, it decides whether it needs to run 5 minutes later or 10
minutes later, and schedules itself appropriately to run once (as opposed to
running indefinitely with a fixed interval).
- Oliver