

/**
 * Does some processing (simulated by sleep).  
 *
 * The thread is implemented through an interface.
 */
public class Counter2 implements Runnable
{
  /** The counters id. */
  private int currentNum;
  /** Loop counts to maximum. */
  private int loopLimit;

  /** The loop limit the the number of units of time. */
  public Counter2(int loopLimit)
  {
    currentNum=Counter.totalNum;
    ++Counter.totalNum;
    this.loopLimit = loopLimit;
  }

  /** Suspend the thread. */
  private void pause(double seconds)
  {
    try
    {
      Thread.sleep(Math.round(1000.0*seconds));
    }
    catch (InterruptedException ie)
    {
    }
  }

  /** The main body of code. */
  public void run()
  {
    for (int i=0; i<loopLimit; ++i)
    {
      System.out.println("Counter2 id:" + currentNum + " i: " + i);
      pause(Math.random());
    }
  }

}


