Source of GreetingProducer.java


  1: /**
  2:    An action that repeatedly prints a greeting.
  3: */
  4: public class GreetingProducer implements Runnable
  5: {
  6:    /**
  7:       Constructs the producer object.
  8:       @param aGreeting the greeting to display
  9:    */
 10:    public GreetingProducer(String aGreeting)
 11:    {
 12:       greeting = aGreeting;
 13:    }

 15:    public void run()
 16:    {
 17:       try 
 18:       {
 19:          for (int i = 1; i <= REPETITIONS; i++)
 20:          {
 21:             System.out.println(i + ": " + greeting);
 22:             Thread.sleep(DELAY);                     
 23:          }
 24:       }
 25:       catch (InterruptedException exception)
 26:       {
 27:       }
 28:    }

 30:    private String greeting;

 32:    private static final int REPETITIONS = 10;
 33:    private static final int DELAY = 100;
 34: }