新的起點(diǎn) 新的開(kāi)始

          快樂(lè)生活 !

          學(xué)習(xí)實(shí)踐 JDK5 concurrent 并行包之CountDownLatch

          CountDownLatch 類跟CyclicBarrier類似,通過(guò)countDown()方法遞減,直到為零,所有被它阻塞的線程被喚起執(zhí)行。
          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 閱讀(734) 評(píng)論(0)  編輯  收藏


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           

          公告

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

          統(tǒng)計(jì)

          常用鏈接

          留言簿(13)

          隨筆分類(71)

          隨筆檔案(179)

          文章檔案(13)

          新聞分類

          IT人的英語(yǔ)學(xué)習(xí)網(wǎng)站

          JAVA站點(diǎn)

          優(yōu)秀個(gè)人博客鏈接

          官網(wǎng)學(xué)習(xí)站點(diǎn)

          生活工作站點(diǎn)

          最新隨筆

          搜索

          積分與排名

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 邓州市| 昌邑市| 咸阳市| 永年县| 定西市| 新巴尔虎左旗| 勃利县| 建阳市| 烟台市| 沙河市| 景洪市| 墨脱县| 兰西县| 左贡县| 金乡县| 客服| 长岛县| 阿巴嘎旗| 临湘市| 牡丹江市| 泸水县| 浮梁县| 乃东县| 隆林| 高安市| 汉川市| 襄汾县| 同江市| 赣州市| 南昌县| 阳山县| 宁陕县| 南开区| 桐城市| 武强县| 肥乡县| 海原县| 南郑县| 宝丰县| 全南县| 富川|