package org.study2.javabase.ThreadsDemo.status; /**
* @Auther:GongXingRui
* @Date:2018/9/19
* @Description: 阻塞进程方法Join
**/
public class ThreadJoin {
public static void main(String args[]) throws InterruptedException {
JoinDemo demo = new JoinDemo();
Thread t = new Thread(demo);
t.start(); for (int i = 0; i < 21; i++) {
if (i == 10) {
// 阻塞main进程,执行线程
t.join();
}
System.out.println("main执行中: " + i);
Thread.sleep(100);
}
}
} class JoinDemo implements Runnable {
@Override
public void run() {
for (int i = 0; i < 21; i++) {
System.out.println("线程执行中: " + i);
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}