1  import java.util.Date;
  2  
  3  /**
  4     A runnable that repeatedly prints a greeting.
  5  */
  6  public class GreetingRunnable implements Runnable
  7  {
  8     private static final int REPETITIONS = 10;
  9     private static final int DELAY = 1000;
 10  
 11     private String greeting;
 12  
 13     /**
 14        Constructs the runnable object.
 15        @param aGreeting the greeting to display
 16     */
 17     public GreetingRunnable(String aGreeting)
 18     {
 19        greeting = aGreeting;
 20     }
 21  
 22     public void run()
 23     {
 24        try
 25        {
 26           for (int i = 1; i <= REPETITIONS; i++)
 27           {
 28              Date now = new Date();
 29              System.out.println(now + " " + greeting);
 30              Thread.sleep(DELAY);         
 31           }
 32        }
 33        catch (InterruptedException exception)
 34        {
 35        }
 36     }
 37  }