package study_02;
public class Test6 {
public static void main(String[] args) throws InterruptedException {
Thread t = new Thread(()-> {
for (int i = 0; i < 110; i++) {
System.out.println("insert---->" + i);
}
});
t.start();
for (int i = 0; i < 100; i++) {
if (i == 20) {//当i=20时阻塞主线程,
t.join();//插队
}else {
System.out.println("main---->" + i);
}
}
}
}
一开始主线程和t线程交替运行,当i=20时主线程阻塞,运行t线程.