From a559137c8c31028fc0b757f86f2656d49122b438 Mon Sep 17 00:00:00 2001 From: RanjeetKaur17 Date: Wed, 24 Oct 2018 23:05:27 +0400 Subject: [PATCH] Changes as per review comments --- .../countdownlatch/CountdownLatchResetExample.java | 7 ++++--- .../cyclicbarrier/CyclicBarrierCountExample.java | 2 +- .../cyclicbarrier/CyclicBarrierResetExample.java | 6 +++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/core-java-concurrency/src/main/java/com/baeldung/concurrent/countdownlatch/CountdownLatchResetExample.java b/core-java-concurrency/src/main/java/com/baeldung/concurrent/countdownlatch/CountdownLatchResetExample.java index 7effc9e374..55e509e374 100644 --- a/core-java-concurrency/src/main/java/com/baeldung/concurrent/countdownlatch/CountdownLatchResetExample.java +++ b/core-java-concurrency/src/main/java/com/baeldung/concurrent/countdownlatch/CountdownLatchResetExample.java @@ -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"); + } }); } diff --git a/core-java-concurrency/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCountExample.java b/core-java-concurrency/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCountExample.java index c7a9b20698..9d637b428b 100644 --- a/core-java-concurrency/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCountExample.java +++ b/core-java-concurrency/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCountExample.java @@ -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()); } } diff --git a/core-java-concurrency/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierResetExample.java b/core-java-concurrency/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierResetExample.java index c355b7eead..febeb0978e 100644 --- a/core-java-concurrency/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierResetExample.java +++ b/core-java-concurrency/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierResetExample.java @@ -28,8 +28,8 @@ 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) { e.printStackTrace(); @@ -41,7 +41,7 @@ public class CyclicBarrierResetExample { } public static void main(String[] args) { - CyclicBarrierResetExample ex = new CyclicBarrierResetExample(new ArrayList(), 5, 20); + CyclicBarrierResetExample ex = new CyclicBarrierResetExample(new ArrayList(), 7, 20); System.out.println("Count : " + ex.countWaits()); } }