How to schedule a task in java ?
Few java applications are required to update something after a period of time - and that too automatically or without manual intervention.
To do so, in Java, we can perform below steps to complete this task,
------------------------------ScheduleTask.java---------------------------
public class ScheduledTask extends TimerTask {
public void run() {
System.out.println(" scheduler enabled on " + new Date().getTime());
//you can perform any operation required as per your need here
}
}
--------------------RunScheduledTask.java------------------------------
public class RunScheduledTask{
public static void main(String args[]){
Timer time = new Timer(); // Instantiate Timer Object
ScheduleTask st = new ScheduleTask();
time.schedule(st, 0, 86400000);// scheduled for one day
}
}
No comments:
Post a Comment