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后再执行主线程

posted @ 2022-07-14 15:57  小布丁dd  阅读(21)  评论(0)    收藏  举报