Join
Join合并线程,待此线程执行完成后,在执行其它线程,其它线程阻塞,可以想象成插队。
package 线程状态;
public class JoinThread implements Runnable{
public void run() {
for(int i = 0 ; i < 10 ; i++) {
System.out.println("vip线程来了" + i);
}
}
public static void main(String[] args) throws InterruptedException {
//启动线程
JoinThread jt = new JoinThread();
Thread thread = new Thread(jt);
thread.start();
//主线程
for(int i = 0 ; i < 10 ; i++) {
if(i == 2) {
thread.join(); //插队
}
System.out.println("main线程"+ i);
}
}
}