Changes as per review comments

This commit is contained in:
RanjeetKaur17 2018-10-24 23:05:27 +04:00
parent e5f43622be
commit a559137c8c
3 changed files with 8 additions and 7 deletions

View File

@ -23,10 +23,11 @@ public class CountdownLatchResetExample {
ExecutorService es = Executors.newFixedThreadPool(threadCount); ExecutorService es = Executors.newFixedThreadPool(threadCount);
for (int i = 0; i < threadCount; i++) { for (int i = 0; i < threadCount; i++) {
es.execute(() -> { es.execute(() -> {
if (countDownLatch.getCount() > 0) { long prevValue = countDownLatch.getCount();
outputScraper.add("Count Left : " + countDownLatch.getCount());
}
countDownLatch.countDown(); countDownLatch.countDown();
if (countDownLatch.getCount() != prevValue) {
outputScraper.add("Count Updated");
}
}); });
} }

View File

@ -26,7 +26,7 @@ public class CyclicBarrierCountExample {
} }
public static void main(String[] args) { public static void main(String[] args) {
CyclicBarrierCountExample ex = new CyclicBarrierCountExample(1); CyclicBarrierCountExample ex = new CyclicBarrierCountExample(7);
System.out.println("Count : " + ex.callTwiceInSameThread()); System.out.println("Count : " + ex.callTwiceInSameThread());
} }
} }

View File

@ -28,8 +28,8 @@ public class CyclicBarrierResetExample {
es.execute(() -> { es.execute(() -> {
try { try {
if (cyclicBarrier.getNumberWaiting() > 0) { if (cyclicBarrier.getNumberWaiting() > 0) {
outputScraper.add("Waiting Count : " + cyclicBarrier.getNumberWaiting()); outputScraper.add("Count Updated");
} }
cyclicBarrier.await(); cyclicBarrier.await();
} catch (InterruptedException | BrokenBarrierException e) { } catch (InterruptedException | BrokenBarrierException e) {
e.printStackTrace(); e.printStackTrace();
@ -41,7 +41,7 @@ public class CyclicBarrierResetExample {
} }
public static void main(String[] args) { 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()); System.out.println("Count : " + ex.countWaits());
} }
} }