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

3.1.6 循环栅栏:CyclicBarrier

时间:2018-02-07 12:02:14      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:catch   sleep   dex   stat   interrupt   join   adf   public   bar   

package 第三章.循环栅栏CyclicBarrier;

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

/**
* Created by zzq on 2018/1/24.
*/
public class CyclicBarrierTeST implements Runnable{
static CyclicBarrier cyclicBarrier=new CyclicBarrier(2);
public void run() {
System.out.println(Thread.currentThread().getName()+"准备开始");
try {
Thread.sleep(2000);
cyclicBarrier.await();
System.out.println(Thread.currentThread().getName()+"开始工作-------");
} catch (InterruptedException e) {
e.printStackTrace();
} catch (BrokenBarrierException e) {
e.printStackTrace();
}
}

public static void main(String[] args) throws BrokenBarrierException, InterruptedException {
CyclicBarrierTeST cyclicBarrierTeST=new CyclicBarrierTeST();
System.out.println("开始执行程序");
Thread thread=new Thread(cyclicBarrierTeST);
Thread thread2=new Thread(cyclicBarrierTeST);
thread.start();
thread2.start();
thread.join();
thread2.join();
System.out.println("fdsafsadfsadas");
}
}

3.1.6 循环栅栏:CyclicBarrier

标签:catch   sleep   dex   stat   interrupt   join   adf   public   bar   

原文地址:https://www.cnblogs.com/anxbb/p/8425548.html

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