新的起點(diǎn) 新的開始

          快樂生活 !

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

          CountDownLatch 類跟CyclicBarrier類似,通過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 閱讀(735) 評(píng)論(0)  編輯  收藏


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


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

          公告

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

          統(tǒng)計(jì)

          常用鏈接

          留言簿(13)

          隨筆分類(71)

          隨筆檔案(179)

          文章檔案(13)

          新聞分類

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

          JAVA站點(diǎn)

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

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

          生活工作站點(diǎn)

          最新隨筆

          搜索

          積分與排名

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 宜黄县| 文登市| 乌苏市| 海兴县| 韶山市| 万宁市| 两当县| 获嘉县| 武义县| 梁平县| 雷波县| 桂平市| 临沭县| 洛阳市| 连江县| 闽清县| 娄烦县| 视频| 米脂县| 高陵县| 汕头市| 哈巴河县| 宁夏| 盖州市| 汤原县| 台东市| 清远市| 宣恩县| 山阳县| 林芝县| 昌邑市| 红河县| 金山区| 伊吾县| 长兴县| 郧西县| 江永县| 象山县| 响水县| 湖北省| 通城县|