How to write Scheduler in Java
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
/**
* This Class is Used to Run Every after 15 min
*
* @author ananddw
**/
public class TestScheduler{
public static void main(String[] args) {
new TestScheduler().start();
}
public void start() {
System.out.println(" scheduler starts");
Executors.newSingleThreadScheduledExecutor().scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
try {
//Need to Call Your Method which will execute every after 15 min
System.out.println(new java.util.Date());
} catch (Throwable e) {
System.out.println("--Error in Schduler--");
e.printStackTrace();
}
}
}, 0, 15, TimeUnit.MINUTES);
}
}
Comments
Post a Comment