新的起點 新的開始

          快樂生活 !

          學習實踐 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站點

          優秀個人博客鏈接

          官網學習站點

          生活工作站點

          最新隨筆

          搜索

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 吉首市| 凌海市| 和田市| 大荔县| 桂林市| 宣武区| 宁河县| 牙克石市| 旬阳县| 丰宁| 自治县| 城步| 云南省| 那坡县| 阿尔山市| 九龙城区| 罗定市| 宁晋县| 老河口市| 宝坻区| 远安县| 英吉沙县| 慈利县| 长阳| 通辽市| 辉县市| 北碚区| 古浪县| 明水县| 樟树市| 梅州市| 洛川县| 梁河县| 石河子市| 阳曲县| 开原市| 阿克苏市| 临泽县| 南宁市| 青田县| 珲春市|