Concurrency Coordination Reports
Atomic Counter Coordination Report
Accumulate a shared count with an atomic integer and classify the result.
atomic counter
An `AtomicInteger` keeps a running total consistent even when several workers update it, so a coordination report can read one final value.
Atomic Counter Coordination Report
AtomicCounterCoordinationReport.java
Replay: real traced execution (multi-file project)
import java.util.concurrent.atomic.AtomicInteger;
public class AtomicCounterCoordinationReport {
public static void main(String[] args) {
int step = 2;
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 = 1;
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 = 3;
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);
}
}
step ← 2, counter ← 0
3public class AtomicCounterCoordinationReport {4 public static void main(String[] args) {5 int step→ 2 = 2; //@step=1, 36 AtomicInteger counter→ 0 = new AtomicInteger(0);for (int i = 0; i < 4; i++)
pass 1 of 48for (int i0 = 0; i < 4; i++) {9 counter.addAndGet(step2);10}All 4 passes — pass 1 is the card above pass i1 0 2 1 3 2 4 3 total ← 8, status ← ok
12 int total→ 8 = counter.get();13 String status→ ok = total8 <= 4 ? "low" : total <= 8 ? "ok" : "high";1415 System.out.println("step=" + step2 + " total=" + total8 + " status=" + statusok);16}outputstep=2 total=8 status=ok
step ← 1, counter ← 0
3public class AtomicCounterCoordinationReport {4 public static void main(String[] args) {5 int step→ 1 = 1;6 AtomicInteger counter→ 0 = new AtomicInteger(0);for (int i = 0; i < 4; i++)
pass 1 of 48for (int i0 = 0; i < 4; i++) {9 counter.addAndGet(step1);10}All 4 passes — pass 1 is the card above pass i1 0 2 1 3 2 4 3 total ← 4, status ← low
12 int total→ 4 = counter.get();13 String status→ low = total4 <= 4 ? "low" : total <= 8 ? "ok" : "high";1415 System.out.println("step=" + step1 + " total=" + total4 + " status=" + statuslow);16}outputstep=1 total=4 status=low
step ← 3, counter ← 0
3public class AtomicCounterCoordinationReport {4 public static void main(String[] args) {5 int step→ 3 = 3;6 AtomicInteger counter→ 0 = new AtomicInteger(0);for (int i = 0; i < 4; i++)
pass 1 of 48for (int i0 = 0; i < 4; i++) {9 counter.addAndGet(step3);10}All 4 passes — pass 1 is the card above pass i1 0 2 1 3 2 4 3 total ← 12, status ← high
12 int total→ 12 = counter.get();13 String status→ high = total12 <= 4 ? "low" : total <= 8 ? "ok" : "high";1415 System.out.println("step=" + step3 + " total=" + total12 + " status=" + statushigh);16}outputstep=3 total=12 status=high