Scheduler in Java | Code Factory

Donate : Link

Reference : Link

Applications : Link

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);
}
}