How do I schedule a task to run at a certain time?

John Zukowski

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


long now = System.currentTimeMillis();
Date whenToRun = new Date(now+millisecondsInFuture);
Timer timer = new Timer();
TimerTask task = new TimerTask() {
  public void run() {
    // job code here
  }
};
timer.schedule(task, whenToRun);
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


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

 

 

About | Sitemap | Contact