001package edu.pdx.cs410J.net;
002
003/**
004 * A <code>Counter</code> is something that counts in its own thread.
005 */
006public class Counter extends Thread {
007
008  private String name;
009
010  /**
011   * Creates a new <code>Counter</code> with a given name
012   */
013  public Counter(String name) {
014    this.name = name;
015  }
016
017  /**
018   * The code that performs the counting.
019   */
020  public void run() {
021    // Wait for a random amount of time and then print a number
022    for (int i = 1; i <= 6; i++) {
023      try {
024        long time = (long) (Math.random() * 1000);
025
026        Thread.sleep(time);
027
028      } catch (InterruptedException ex) {
029        return;
030      }
031
032      System.out.println(this.name + ": " + i);
033    }
034  }
035
036}