java - Synchronized does not work by cyclic barrier -
public class test { final int counter = 0; // may different number int add = 0; public synchronized void testsync() throws interruptedexception { add++; if (add == counter) { add = 0; notifyall(); } else { while (add > 0) { wait(); } } } }
how can fix code make work?i need make work cyclic barrier.
public class test { final int counter = 0; // may different number final cyclicbarrier barrier = new cyclicbarrier(counter); public void testsync() throws interruptedexception, brokenbarrierexception { barrier.await(); } }
Comments
Post a Comment