java.util.TimerTask.scheduledExecutionTime() Method



Description

The scheduledExecutionTime() method is used to return the scheduled execution time of the most recent actual execution of this task.

Declaration

Following is the declaration for java.util.TimerTask.scheduledExecutionTime() method.

public long scheduledExecutionTime()

Parameters

NA

Return Value

The method call returns the time at which the most recent execution of this task was scheduled to occur.

Exception

NA

Example

The following example shows the usage of java.util.TimerTask.scheduledExecutionTime()

package com.tutorialspoint;

import java.util.*;

public class TimerTaskDemo {
   public static void main(String[] args) {
      
      // creating timer task, timer
      TimerTask task = new TimerTaskCancel();
      Timer timer = new Timer();

      // scheduling the task
      timer.scheduleAtFixedRate(task, new Date(), 1000);

      // checking scheduled execution time
      System.out.println("Time is :"+task.scheduledExecutionTime());
   }
   // this method performs the task
   
   public void run() {
      System.out.println("Working on the task assigned");      
   }    
}

Let us compile and run the above program, this will produce the following result.

Time is :1335444782599
Working
Working
Working
Working
Working
Working and so on
java_util_timertask.htm
Advertisements