首页 > 其他 > 详细

CountDownLatchTest

时间:2014-12-24 17:44:06      阅读:102      评论:0      收藏:0      [点我收藏+]

import java.util.concurrent.CountDownLatch;

/**
* 出发点:等待所有线程执行完成
* @author yinchuan.chen
*
*/
public class CountDownLatchTest {

public static void main(String[] args) throws InterruptedException {
CountDownLatch cdl = new CountDownLatch(4);
for(int i = 0; i < 4; i++) {
final int count = i;
Thread t = new Thread(new Runnable() {

public void run() {
System.out.println(count);
cdl.countDown();
}
});

t.start();
}

cdl.await();
System.out.println("等所有现场执行完成,才打印");

}
}

CountDownLatchTest

原文:http://www.cnblogs.com/hellocyc/p/4182813.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!