CyclicBarrier 类的使用大可以家自行百度,有好多写的很详细
final CyclicBarrier num =new CyclicBarrier(5);
for (int i =0; i <5; i++) {
new Thread(new Runnable() {
@Override
public void run() {
try {
System.out.println("hello");
num.await();
System.out.println("world");
}catch (Exception e){
}
}
}).start();
}
网友评论