Concurrency Coordination Reports
Atomic Counter Coordination Report
Accumulate a shared count with an atomic integer and classify the result.
Atomic Counter Coordination Report
AtomicCounterCoordinationReport.java
import java.util.concurrent.atomic.AtomicInteger;
public class AtomicCounterCoordinationReport {
public static void main(String[] args) {
int step = ;
AtomicInteger counter = new AtomicInteger(0);
for (int i = 0; i < 4; i++) {
counter.addAndGet(step);
}
int total = counter.get();
String status = total <= 4 ? "low" : total <= 8 ? "ok" : "high";
System.out.println("step=" + step + " total=" + total + " status=" + status);
}
}
import java.util.concurrent.atomic.AtomicInteger;
public class AtomicCounterCoordinationReport {
public static void main(String[] args) {
int step = ;
AtomicInteger counter = new AtomicInteger(0);
for (int i = 0; i < 4; i++) {
counter.addAndGet(step);
}
int total = counter.get();
String status = total <= 4 ? "low" : total <= 8 ? "ok" : "high";
System.out.println("step=" + step + " total=" + total + " status=" + status);
}
}
import java.util.concurrent.atomic.AtomicInteger;
public class AtomicCounterCoordinationReport {
public static void main(String[] args) {
int step = ;
AtomicInteger counter = new AtomicInteger(0);
for (int i = 0; i < 4; i++) {
counter.addAndGet(step);
}
int total = counter.get();
String status = total <= 4 ? "low" : total <= 8 ? "ok" : "high";
System.out.println("step=" + step + " total=" + total + " status=" + status);
}
}
atomic counter
An `AtomicInteger` keeps a running total consistent even when several workers update it, so a coordination report can read one final value.