How do I schedule a task to run repeatedly?

John Zukowski

Use the scheduleAtFixedRate() method of the java.util.Timer class:


int initialDelay = 30000; // start after 30 seconds
int period = 5000;        // repeat every 5 seconds
Timer timer = new Timer();
TimerTask task = new TimerTask() {
  public void run() {
    // job code here
  }
};
timer.scheduleAtFixedRate(task, initialDelay, period);
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact