Java TimerTask .scheduledExecutionTime ()

Syntax

TimerTask.scheduledExecutionTime() has the following syntax.

public long scheduledExecutionTime()

Example

In the following code shows how to use TimerTask.scheduledExecutionTime() method.


/*from  w  ww.j  a v a  2 s  . c o m*/
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

class MyTimerTask extends TimerTask {
  public void run() {
    System.out.println("Timer task executed.");
  }
}

public class Main {
   public static void main(String[] args) {
      // creating timer task, timer
      TimerTask task = new MyTimerTask();
      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");      
   }    
}

The code above generates the following result.