Wednesday 6 February 2019

How to find the scheduled execution time of the most recent actual execution of the task


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

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

    }

}

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...

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:

  • All JavaEE Videos Playlist
  • All JavaEE Videos
  • All JAVA EE Links
  • Spring Tutorial
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • Cooking Tutorial
  • No comments:

    Post a Comment