// example of using java.util.Timer
import java.util.Timer;
import java.util.TimerTask;

...

/**
 * set up an event to happen later
 * @param delayInMillis how long to wait
 */
public void doLater( long delayInMillis )
   {
   // one shot
   new Timer().schedule( new ScheduleRunner(), delayInMillis );
   // repeat
   new Timer().schedule( new ScheduleRunner(), delayInMillis /* delay */, delayInMillis /* period */);
   }

/**
 * run method will be invoked when time is up.
 */
class ScheduleRunner extends TimerTask
   {
   /**
    * executed when time is up.
    */
   public void run()
      {
      doSomething();
      }
   } // end inner class ScheduleRunner

// The problem with Timer is shutting it down.
// Your program will not exit until you do, or you use System.exit.
// Timer.cancel stops the timer, but I am not sure if it shuts down the thread.

////////////////////////////////////////////////////////////////////

// If you want a timer you can shutdown down easily, do it this way:

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;

private static ScheduledExecutorService scheduler;
...
   scheduler = Executors.newSingleThreadScheduledExecutor();
   scheduler.scheduleAtFixedRate( new Runnable()
        {
        public void run()
            {
            doSomething();
            }
        }, 5, 5, TimeUnit.SECONDS );  // terser with lambdas.
...
   // shutdown that kills both timer and thread
   scheduler.shutdownNow();