This Java tip illustrates a method of scheduling a timer for a task to run repeatedly. Developer may use this code if there is a need to execute or repeat a task in an application at a predefined interval of time.

  int delay = 5000;   // delay for 5 sec.
    int interval = 1000;  // iterate every sec.
    Timer timer = new Timer();
    timer.scheduleAtFixedRate(new TimerTask() {
            public void run() {
                // Task here ...
        }, delay, interval);