Timer.schedule(TimerTask task, long delay) has the following syntax.
public void schedule(TimerTask task, long delay)
In the following code shows how to use Timer.schedule(TimerTask task, long delay) method.
/*from w ww .ja v a 2 s. c o m*/ 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); } // this method performs the task public void run() { System.out.println("timer working"); } }
The code above generates the following result.