📄 jointhread.java
字号:
class JoinThread extends Thread{
String name;
JoinThread(String threadName){
name = threadName;
}
public void run(){
try{
for(int i = 1;i<6;i++){
System.out.println(name+":"+i);
Thread.sleep(1000);
}
}catch(InterruptedException e){}
System.out.println(name+"exiting.");
}
public static void main(String args[]){
JoinThread t1 = new JoinThread("线程1");
JoinThread t2 = new JoinThread("线程2");
JoinThread t3 = new JoinThread("线程3");
t1.start();
t2.start();
t3.start();
System.out.println("线程1是激活的:"+t1.isAlive());
System.out.println("线程2是激活的:"+t2.isAlive());
System.out.println("线程3是激活的:"+t3.isAlive());
try{
System.out.println("等待进程运行完毕。");
t1.join();
t2.join();
t3.join();
}catch(InterruptedException e){}
System.out.println("线程1是激活的:"+t1.isAlive());
System.out.println("线程2是激活的:"+t2.isAlive());
System.out.println("线程3是激活的:"+t3.isAlive());
System.out.println("主线程结束");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -