add answers.md
This commit is contained in:
@@ -52,19 +52,7 @@ public class BankAccount {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO:
|
||||
* Transfer money between two accounts atomically.
|
||||
*
|
||||
* IMPORTANT REQUIREMENTS:
|
||||
* - Must be atomic (no partial transfer)
|
||||
* - Must be deadlock-free
|
||||
* - Must protect both source and target accounts
|
||||
*
|
||||
* HINT:
|
||||
* - Consider global lock ordering using accountId
|
||||
* - Or tryLock with retry strategy
|
||||
*/
|
||||
|
||||
public void transfer(BankAccount target, long amount) {
|
||||
BankAccount first = this.accountId < target.accountId ? this : target;
|
||||
BankAccount second = this.accountId > target.accountId ? this : target;
|
||||
|
||||
Reference in New Issue
Block a user