Code Room
Code reviewHard
Question
Review this Java metrics registry. `record` is the hot path; it lazily creates a counter under a read lock then upgrades to write.
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
private final ReadWriteLock rw = new ReentrantReadWriteLock();private final Map<String, AtomicLong> counters = new HashMap<>(); void record(String name) { rw.readLock().lock(); if (!counters.containsKey(name)) { rw.writeLock().lock(); // upgrade counters.put(name, new AtomicLong()); rw.writeLock().unlock(); } counters.get(name).incrementAndGet(); rw.readLock().unlock();}Run or narrate your approach, then ask the coach.