Code Room
Code reviewMedium
Question
Review this Java rate-limiter counter that uses atomics.
Does the use of AtomicInteger make this thread-safe?
What a strong answer looks like
Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix — specific and kind.
Learn the concepts
class Limiter { private final AtomicInteger count = new AtomicInteger(0); private final int max; Limiter(int max) { this.max = max; } boolean tryAcquire() { if (count.get() < max) { // (1) read count.incrementAndGet(); // (2) read-modify-write return true; } return false; } void release() { count.decrementAndGet(); }}Run or narrate your approach, then ask the coach.