Click here to watch on Youtube:
https://www.youtube.com/watch?v=HTRdIh1A_rc&list=UUhwKlOVR041tngjerWxVccw
ReminderTimerTask.java
import java.util.TimerTask;
public class ReminderTimerTask extends TimerTask
{
public void run()
{
System.out.println("Wake up...");
}
}
public class ReminderTimerTask extends TimerTask
{
public void run()
{
System.out.println("Wake up...");
}
}
TimerDemo.java
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
public class TimerDemo
{
public static void main(String[] args) throws InterruptedException
{
Timer timer = new Timer();
TimerTask reminderTimerTask = new ReminderTimerTask();
timer.schedule(reminderTimerTask, 5000, 2000);
System.out.println("Timer has schedule the reminderTimerTask...");
/*
* Returns:
*
* the time at which the most recent execution of this task
* was scheduled to occur, in the format returned by
* Date.getTime(). The return value is undefined if the task
* has yet to commence its first execution.
*/
long scheduledExecutionTime = reminderTimerTask
.scheduledExecutionTime();
System.out.println(
"scheduledExecutionTime = " + new Date(scheduledExecutionTime));
}
}
import java.util.Timer;
import java.util.TimerTask;
public class TimerDemo
{
public static void main(String[] args) throws InterruptedException
{
Timer timer = new Timer();
TimerTask reminderTimerTask = new ReminderTimerTask();
timer.schedule(reminderTimerTask, 5000, 2000);
System.out.println("Timer has schedule the reminderTimerTask...");
/*
* Returns:
*
* the time at which the most recent execution of this task
* was scheduled to occur, in the format returned by
* Date.getTime(). The return value is undefined if the task
* has yet to commence its first execution.
*/
long scheduledExecutionTime = reminderTimerTask
.scheduledExecutionTime();
System.out.println(
"scheduledExecutionTime = " + new Date(scheduledExecutionTime));
}
}
Output:
Timer has schedule the reminderTimerTask...
scheduledExecutionTime = Sat Feb 02 09:18:20 IST 2019
Wake up...
Wake up...
Wake up...
Wake up...
Wake up...
scheduledExecutionTime = Sat Feb 02 09:18:20 IST 2019
Wake up...
Wake up...
Wake up...
Wake up...
Wake up...
Click the below link to download the code:
https://sites.google.com/site/javaspringram2019/java_spring_2019/TimerDemo_scheduledExecutionTime.zip?attredirects=0&d=1
Github Link:
https://github.com/ramram43210/Java_Spring_2019/tree/master/Java_2019/TimerDemo_scheduledExecutionTime
Bitbucket Link:
https://bitbucket.org/ramram43210/java_spring_2019/src/7a570b442b7e7cac6e2bc811d1d0cc686cb3a5c1/Java_2019/TimerDemo_scheduledExecutionTime/?at=master
See also:
No comments:
Post a Comment