`
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);
}
}
}
网友评论