📄 lx6_2.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 + -