首页 > 其他 > 详细

CyclicBarrier

时间:2014-08-27 00:22:26      阅读:291      评论:0      收藏:0      [点我收藏+]

package com.alibaba.yuanmeng._concurrent;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

public class CyclicBarrierTest {
private static final int THREAD_COUNT = 10;

public static CyclicBarrier barrier = new CyclicBarrier(THREAD_COUNT);

public static void main(String[] args) {
for(int i = 0; i<THREAD_COUNT; i++){
new Thread(new WorkThread(barrier)).start();
}
}

}

class WorkThread implements Runnable{
private CyclicBarrier barrier;

public WorkThread(CyclicBarrier barrier){
this.barrier = barrier;
}

@Override
public void run() {
try {
System.out.println(Thread.currentThread().getName() + "working before await()");
barrier.await();
System.out.println(Thread.currentThread().getName() + "working after await()");
} catch (InterruptedException e) {
e.printStackTrace();
} catch (BrokenBarrierException e) {
e.printStackTrace();
}
}
}

CyclicBarrier

原文:http://www.cnblogs.com/chenmo-xpw/p/3938454.html

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