码迷,mamicode.com
首页 > 其他好文 > 详细

CountDownLatchTest

时间:2014-12-24 17:46:41      阅读:162      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!