新的起點 新的開始

          快樂生活 !

          學習實踐 JDK5 concurrent 并行包之CountDownLatch

          CountDownLatch 類跟CyclicBarrier類似,通過countDown()方法遞減,直到為零,所有被它阻塞的線程被喚起執行。
          1 package net.vincent.study.other;
           2 
           3 import java.util.concurrent.CountDownLatch;
           4 
           5 public class part2 {
           6     public static void main(String[] agrs){
           7         CountDownLatch countDownlatch = new CountDownLatch(2);
           8         new testThread("threadOne",countDownlatch).start();
           9         new testThread("threadOne",countDownlatch).start();
          10         
          11         
          12     }
          13 }
          14 class testThread extends Thread {
          15     CountDownLatch countDownlatch;
          16     public testThread(String threadName,CountDownLatch countDownlatch){
          17         super(threadName);
          18         this.countDownlatch = countDownlatch;
          19     }
          20     public void run(){
          21         System.out.print(this.getName()+"  running  ");
          22         try {
          23             
          24             countDownlatch.countDown();
          25             System.out.println("count is "+countDownlatch.getCount());
          26             countDownlatch.await();
          27         } catch (InterruptedException e) {
          28             e.printStackTrace();
          29         }
          30         System.out.println(this.getName()+" Done");
          31     }
          32 }
          33 

          posted on 2007-09-28 16:04 advincenting 閱讀(735) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          公告

          Locations of visitors to this pageBlogJava
        1. 首頁
        2. 新隨筆
        3. 聯系
        4. 聚合
        5. 管理
        6. <2007年9月>
          2627282930311
          2345678
          9101112131415
          16171819202122
          23242526272829
          30123456

          統計

          常用鏈接

          留言簿(13)

          隨筆分類(71)

          隨筆檔案(179)

          文章檔案(13)

          新聞分類

          IT人的英語學習網站

          JAVA站點

          優秀個人博客鏈接

          官網學習站點

          生活工作站點

          最新隨筆

          搜索

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 玉林市| 中宁县| 千阳县| 奇台县| 临桂县| 安平县| 永丰县| 花莲县| 平泉县| 庆云县| 纳雍县| 嵩明县| 香格里拉县| 偃师市| 南开区| 深水埗区| 麻阳| 合阳县| 晋中市| 麻栗坡县| 蓝山县| 上饶市| 泽州县| 萨嘎县| 马龙县| 南召县| 军事| 溆浦县| 军事| 巴彦县| 临夏市| 大悟县| 民丰县| 宜兴市| 浮梁县| 大新县| 定边县| 聂荣县| 毕节市| 绥阳县| 海丰县|