⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lx6_2.java

📁 针对越来越多的用户喜欢JAVA
💻 JAVA
字号:
class MyThread extends Thread
   { 
    int n;
    String s;
    Thread td;
    MyThread (String str)
	{
        s=str;
	td=new Thread(this);
	td.start();
	}
    public void run()
	{
	for (n=0;n<6;n++)
	   {
	    try
	      {
	      System.out.print(s);
              Thread.sleep(250);
	      }
	   catch(InterruptedException e)
	      {
	      System.out.println("Exception1");
	      }
          }
       }
    }
public class Lx6_2
{
    public static void main(String args[])
       {
	MyThread a=new MyThread ("a");
	MyThread b=new MyThread ("b");
	MyThread c=new MyThread ("c");
	System.out.println("Thread a(alive):"+a.td.isAlive());
    System.out.println("Thread b(alive):"+b.td.isAlive());
    System.out.println("Thread c(alive):"+c.td.isAlive());  	
	try
	  {
	   a.td.join();
	   b.td.join(); 
	   c.td.join();	
	  }
	catch(InterruptedException e)
	  {
	  System.out.println("Exception2");
	  }
       System.out.println();
       System.out.println("Thread a(alive):"+a.td.isAlive());
       System.out.println("Thread b(alive):"+b.td.isAlive());
       System.out.println("Thread c(alive):"+c.td.isAlive());   
       }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -