
Implement a class AccountService that supports basic money operations on accounts.
deposit(accountId, amount)
withdraw(accountId, amount)
transfer(fromAccountId, toAccountId, amount)
getBalance(accountId)
amount
is a positive integer.
withdraw
must fail (return
false
or throw) if the account has insufficient funds.
transfer
must be
atomic
: either both balances change, or neither changes.
Assume these methods may be called concurrently from multiple threads. Make the implementation thread-safe and avoid deadlocks.
This is an in-memory class design question; you do not need to build a database or persistence.