Code Room
Code reviewHardcr-g017
Subject DeadlocksLevel Senior–Staff~30 minCommon in Concurrency interviewsIndustries Software development

Question

Review this Java cache that notifies observers under its lock.

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
public class StateStore {    private final Object lock = new Object();    private final Map<String, String> state = new HashMap<>();    private final List<Observer> observers = new ArrayList<>();     public void put(String k, String v) {        synchronized (lock) {            state.put(k, v);            for (Observer o : observers) o.onChange(k, v);        }    }}
Run or narrate your approach, then ask the coach.