最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

java 中Thread.join()的使用方法

 更新時(shí)間:2017年04月06日 09:59:04   投稿:lqh  
這篇文章主要介紹了java 中Thread.join()的使用方法的相關(guān)資料,需要的朋友可以參考下

java 中Thread.join()的使用方法

如果一個(gè)線程A執(zhí)行了thread.join()語(yǔ)句,其含義是:當(dāng)前線程A等待thread線程終止之后才從thread.join()返回。

import java.util.concurrent.TimeUnit;

/**
 * 6-13
 */
public class Join {
 public static void main(String[] args) throws Exception {
  Thread previous = Thread.currentThread();
  for (int i = 0; i < 10; i++) {
   // 每個(gè)線程擁有前一個(gè)線程的引用,需要等待前一個(gè)線程終止,才能從等待中返回
   Thread thread = new Thread(new Domino(previous), String.valueOf(i));
   thread.start();
   previous = thread;
  }

  TimeUnit.SECONDS.sleep(5);
  System.out.println(Thread.currentThread().getName() + " terminate.");
 }

 static class Domino implements Runnable {
  private Thread thread;

  public Domino(Thread thread) {
   this.thread = thread;
  }

  public void run() {
   try {
    thread.join();
   } catch (InterruptedException e) {
   }
   System.out.println(Thread.currentThread().getName() + " terminate.");
  }
 }
}

執(zhí)行結(jié)果:

main terminate.
0 terminate.
1 terminate.
2 terminate.
3 terminate.
4 terminate.
5 terminate.
6 terminate.
7 terminate.
8 terminate.
9 terminate.
 

相關(guān)文章

最新評(píng)論

白沙| 开阳县| 延川县| 潮州市| 姚安县| 虎林市| 灵宝市| 吉木萨尔县| 九江县| 洪洞县| 德钦县| 东乡县| 肇州县| 河间市| 凌海市| 武邑县| 安图县| 万山特区| 安远县| 宝鸡市| 靖安县| 望都县| 新郑市| 满洲里市| 油尖旺区| 汝城县| 泸溪县| 清流县| 康乐县| 报价| 安溪县| 五原县| 壶关县| 尼玛县| 西乡县| 盱眙县| 都昌县| 藁城市| 新津县| 南城县| 盐山县|