// This file defines class "MyThread".  "MyThread" extends the pre-defined
// class "Thread".  This allows instances of class "MyThread" to run as
// separate threads.  Refer to file MainMethod.java to see how instances
// of class "MyThread" are created and started up.

public class MyThread extends Thread {
  String MyName;  // Saves the name of this thread, passed as a parameter by
                  // the process creating this thread


  // This is the constructor for class MyThread.  It is executed when a
  // new instance of this class is created via 'new MyThread ("SomeName")'
  public MyThread(String name) {
    MyName = name;  // copy the parameter value to local variable "MyName"
  }  // end of the constructor



  public void run () {
    for (int I = 0;  I < 25; I++) {
      System.out.println("This is thread " + MyName + " speaking");

      // Sleep between 1 and 201 milliseconds (i.e., up to 0.2 seconds).
      try { sleep((int)(200*Math.random()+1)); } catch(Exception e) {}
  
    } // end of "for" loop
  }  // end of "run" method
}  // end of class "MyThread"

