/*ch1006.java*/
class MyThread extends Thread
{
  int msec;
  String name;
  MyThread(String x,int y)
  {
    name=x;
    msec=y;
  }

  public void run()
  {
    System.out.println(name+"is start!");
    try
    {
      for(int i=0;i<3;i++)
      {
        Thread.sleep(msec);
        System.out.println(name);
      }
    }
    catch(InterruptedException e)
    {
      System.out.println("线程中断");
    }
    System.out.println(name+"has finish!");
  }
}

public class ch1006
{
  public static void main(String args[])
  {
    MyThread mt1=new MyThread("mt1",1000);
    MyThread mt2=new MyThread("mt2",500);
    mt1.start();
    mt2.start();
    System.out.println("Is mt1 alive?  "+(mt1.isAlive()?"yes":"no"));
    System.out.println("Is mt2 alive?  "+(mt2.isAlive()?"yes":"no"));
    try
    {
      mt1.join();     //等待线程结束
      System.out.println("mt1结束");
      mt2.join();
      System.out.println("mt2结束");
    }
    catch(InterruptedException e)
    {
      System.out.println("线程中断");
    }
    System.out.println("Is mt1 alive?  "+(mt1.isAlive()?"yes":"no"));
    System.out.println("Is mt2 alive?  "+(mt2.isAlive()?"yes":"no"));
  }
}