public class Test {
final int counter = 0; // it may be a different number
int add = 0;
public synchronized void testSync() throws InterruptedException {
add++;
if (add == counter) {
add = 0;
notifyAll();
} else {
while (add > 0) {
wait();
}
}
}
}我如何修复代码以使其工作?我需要使它作为循环屏障工作。
发布于 2015-07-07 23:31:41
public class Test {
final int counter = 0; // it may be a different number
final CyclicBarrier barrier = new CyclicBarrier(counter);
public void testSync() throws InterruptedException, BrokenBarrierException {
barrier.await();
}
}https://stackoverflow.com/questions/31280779
复制相似问题