join方法
2020-05-10 本文已影响0人
秋秋_6403
join
`
public class TestThreadJoin implements Runnable{
@Override
public void run() {
for(int i = 0; i< 1000;i++){
System.out.println("子线程执行次数"+i);
}
}
public static void main(String[] args) {
TestThreadJoin threadJoin = new TestThreadJoin();
Thread thread = new Thread(threadJoin);
thread.start();
for(int i = 0; i< 10;i++){
if(5 == i){
try {
thread.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.println("主线程执行次数"+i);
}
}
}