新的起点 新的开始

快乐生活 !

学习实践 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 阅读(725) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
 

公告

Locations of visitors to this page

导航

<2007年9月>
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456

统计

常用链接

留言簿(13)

随笔分类(71)

随笔档案(179)

文章档案(13)

新闻分类

IT人的英语学习网站

JAVA站点

优秀个人博客链接

官网学习站点

生活工作站点

最新随笔

搜索

积分与排名

最新评论

阅读排行榜

评论排行榜