Scheduler in Java | Code Factory

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

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store