Timer.schedule(TimerTask task, long delay, long period) has the following syntax.
public void schedule(TimerTask task, long delay, long period)
In the following code shows how to use Timer.schedule(TimerTask task, long delay, long period) method.
/*from w w w . j a va2 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 tasknew = new MyTimerTask(); Timer timer = new Timer(); // scheduling the task at interval timer.schedule(tasknew,100, 100); } // this method performs the task public void run() { System.out.println("timer working"); } }
The code above generates the following result.