lx6_2.java
来自「针对越来越多的用户喜欢JAVA」· Java 代码 · 共 54 行
JAVA
54 行
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 + =
减小字号Ctrl + -
显示快捷键?