Code Room
Code reviewHard
Question
Review this Java money-transfer method.
This runs on many threads; transfers go in both directions between the same accounts.
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
void transfer(Connection conn, long fromId, long toId, long amount) throws SQLException { conn.setAutoCommit(false); lockAndDebit(conn, fromId, amount); // SELECT ... FOR UPDATE on fromId, then UPDATE lockAndCredit(conn, toId, amount); // SELECT ... FOR UPDATE on toId, then UPDATE conn.commit();}Run or narrate your approach, then ask the coach.