Changes as per review comments
This commit is contained in:
parent
e5f43622be
commit
a559137c8c
|
@ -23,10 +23,11 @@ public class CountdownLatchResetExample {
|
|||
ExecutorService es = Executors.newFixedThreadPool(threadCount);
|
||||
for (int i = 0; i < threadCount; i++) {
|
||||
es.execute(() -> {
|
||||
if (countDownLatch.getCount() > 0) {
|
||||
outputScraper.add("Count Left : " + countDownLatch.getCount());
|
||||
}
|
||||
long prevValue = countDownLatch.getCount();
|
||||
countDownLatch.countDown();
|
||||
if (countDownLatch.getCount() != prevValue) {
|
||||
outputScraper.add("Count Updated");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ public class CyclicBarrierCountExample {
|
|||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
CyclicBarrierCountExample ex = new CyclicBarrierCountExample(1);
|
||||
CyclicBarrierCountExample ex = new CyclicBarrierCountExample(7);
|
||||
System.out.println("Count : " + ex.callTwiceInSameThread());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ public class CyclicBarrierResetExample {
|
|||
es.execute(() -> {
|
||||
try {
|
||||
if (cyclicBarrier.getNumberWaiting() > 0) {
|
||||
outputScraper.add("Waiting Count : " + cyclicBarrier.getNumberWaiting());
|
||||
outputScraper.add("Count Updated");
|
||||
}
|
||||
cyclicBarrier.await();
|
||||
} catch (InterruptedException | BrokenBarrierException e) {
|
||||
|
@ -41,7 +41,7 @@ public class CyclicBarrierResetExample {
|
|||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
CyclicBarrierResetExample ex = new CyclicBarrierResetExample(new ArrayList<String>(), 5, 20);
|
||||
CyclicBarrierResetExample ex = new CyclicBarrierResetExample(new ArrayList<String>(), 7, 20);
|
||||
System.out.println("Count : " + ex.countWaits());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue