join(插队)
public class TestJoin implements Runnable{
public void run(){
for(int i=0;i<100;i++){
System.out.println("线程vip来了");}
}
}
public static void main(String args){
//启动线程
TestJoin testjion = new TestJoin();
Thread thread = new Thread(testjion);
thread.start();
//主线程
for(int i=0;i<1000;i++){
if(i=200){
thread.join(); //插队
}
System.out.println("main"+i);
}
}
i=200的时候,开始执行join 执行完join后再执行主线程

浙公网安备 33010602011771号