java.util.TimerTask.run() Method



Description

The run() method takes care of the action to be performed by this timer task.

Declaration

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

public abstract void run()

Parameters

NA

Return Value

NA

Exception

NA

Example

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

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);
   }
   // this method performs the task
   
   public void run() {
      System.out.println("Working");
   }    
}

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

Working
Working
Working
Working
Working
Working
Working and so on .....
java_util_timertask.htm
Advertisements