Posts

Showing posts with the label run task periodically in java

Scheduler in java.

Image
Run task periodically in java or Scheduler in java. FILE :  SchedulerMain.java package com.codeFactory; import java.util.Date; import java.util.TimerTask; public class SchedulerMain extends TimerTask{ Date current; int cnt=0; @Override public void run() { current = new Date(); System.out.println("Current Date and Time : " + current); cnt++; if(cnt==5) { System.out.println("EXIT."); System.exit(0); } } } FILE :  SchedulerCall.java package com.codeFactory; import java.util.Timer; public class SchedulerCall { public static void main(String args[]) { Timer time = new Timer(); SchedulerMain scMain = new SchedulerMain(); time.schedule(scMain, 0, 5000); } }