From de32d5fd2351dba8e5b37cc6a9a005182669b8d9 Mon Sep 17 00:00:00 2001 From: Selebrator Date: Tue, 18 Jun 2019 23:13:44 +0200 Subject: [PATCH] Wozu eigentlich Atmoic? --- src/main/java/_11/_2/alternative/Checkpoint.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/java/_11/_2/alternative/Checkpoint.java b/src/main/java/_11/_2/alternative/Checkpoint.java index c8e3f25..3803b7d 100644 --- a/src/main/java/_11/_2/alternative/Checkpoint.java +++ b/src/main/java/_11/_2/alternative/Checkpoint.java @@ -1,13 +1,10 @@ package _11._2.alternative; -import java.util.concurrent.atomic.AtomicInteger; - public class Checkpoint { - private static AtomicInteger GATHERED = new AtomicInteger(0); - private final Object lock = new Object(); private int groupSize; + private int gathered = 0; public Checkpoint(int groupSize) { this.groupSize = groupSize; @@ -19,10 +16,10 @@ public class Checkpoint { */ public void gather() throws InterruptedException { synchronized(this.lock) { - if(GATHERED.incrementAndGet() != this.groupSize) { + if(++this.gathered != this.groupSize) { this.lock.wait(); } else { - GATHERED.set(0); + this.gathered = 0; System.out.println("Group gathered"); this.lock.notifyAll(); }