Code Room
Code reviewMediumcr-g221
Subject Atomicity violationsLevel Mid–Senior~25 minCommon in Concurrency interviewsIndustries Software development

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.

Talk through your review
Code to reviewjava
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.