Code Room
Code reviewMedium
Question
Review this Java account-transfer routine.
What is the concurrency hazard, and how is it triggered?
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 Account { final Object lock = new Object(); long balance;} void transfer(Account from, Account to, long amt) { synchronized (from.lock) { synchronized (to.lock) { // (1) from.balance -= amt; to.balance += amt; } }}Run or narrate your approach, then ask the coach.