zoukankan      html  css  js  c++  java
  • Thread.join()方法

    import java.util.concurrent.TimeUnit;
    public class newc {
        public static void main(String []args){
    
    ThreadTest t =new ThreadTest();
    Thread tt =new Thread(t);
          tt.start();
    
    
    int flag=0;
    
    
    for(int n1=0;n1<10;n1++)
    {
    
    
        if(flag==0){try{tt.join(10000);}
        catch (Exception e){e.printStackTrace();}
    }
     flag++;   System.out.println(Thread.currentThread().getName()+"--->"+n1);}
    }}
    class ThreadTest  implements Runnable{
    
        public void run() {
    
                for (int i = 1; i < 20; i++) {
                    System.out.println(Thread.currentThread().getName() + "这是运行的第" + i + "秒");
                    try {
                        TimeUnit.SECONDS.sleep(1);
    
                    } catch (InterruptedException e) {
    
                    }
                    if (i == 10) {
                       break;
                    }
                }
    
        }
    
        }

    做到怎么在运行10s的多线程后,main方法中断,用.join()方法

  • 相关阅读:
    [SDOI2015]星际战争
    [SDOI2016]生成魔咒
    hdu3311
    [ZJOI2011]最小割
    P3331 [ZJOI2011]礼物(GIFT)
    [ZJOI2010]贪吃的老鼠
    状压dp-----三进制
    noip2016 天天爱跑步
    概率期望dp
    poj2186
  • 原文地址:https://www.cnblogs.com/otakus/p/12181372.html
Copyright © 2011-2022 走看看