Java TimerTask - scheduledExecutionTime() Method
The java.util.TimerTask.scheduledExecutionTime() method returns the scheduled execution time of the most recent actual execution of this task.
Syntax
public long scheduledExecutionTime()
Parameters
No parameter is required.
Return Value
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.
Exception
NA.
Example:
In the example below, the java.util.TimerTask.scheduledExecutionTime() method is used to get the scheduled execution time of the most recent actual execution of the given task.
import java.util.*; public class MyClass { public static void main(String[] args) { //creating a timer Timer timer = new Timer(); //creating a timertask TimerTask tt = new TimerTask() { public void run() { System.out.println("Working on the task."); }; }; //scheduling the task to be executed //immediately and after that execute //the task at period of 1000 milliseconds timer.schedule(tt, 0, 1000); //checking scheduled execution time System.out.println("Time is :" + tt.scheduledExecutionTime()); } }
The output of the above code will be:
Working on the task. Time is :1620445689194 Working on the task. Working on the task. Working on the task. Working on the task. Working on the task. and so on ...
❮ Java.util - TimerTask