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

CyclicBarrier

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

标签:java   io   for   ar   art   new   on   ad   ef   

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

标签:java   io   for   ar   art   new   on   ad   ef   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!