parties、count为初始化的数目,parties不会改变,而count为每次调用await时递减;
int getParties()
返回参与者数量
public int getParties() {
return parties;
}
void reset()
将屏障重置为其初始状态(即count=parties),如果屏障中还有线程等待,则会抛出BrokenBarrierException异常.
public void reset() {
final ReentrantLock lock = this.lock;
lock.lock();
try {
breakBarrier(); // break the current generation
nextGeneration(); // start a new generation
} finally {
lock.unlock();
}
}
private void breakBarrier() {
generation.broken = true;
count = parties;
trip.signalAll();
}
private void nextGeneration() {
// signal completion of last generation
trip.signalAll();
// set up next generation
count = parties;
generation = new Generation();
}