Develop #1
@@ -35,6 +35,7 @@ public class BankAccount {
|
||||
public void deposit(long amount) {
|
||||
lock.writeLock().lock();
|
||||
try {
|
||||
if (amount < 0) throw new IllegalArgumentException("Amount cannot be negative");
|
||||
balance += amount;
|
||||
}
|
||||
finally {
|
||||
@@ -45,6 +46,8 @@ public class BankAccount {
|
||||
public void withdraw(long amount) {
|
||||
lock.writeLock().lock();
|
||||
try {
|
||||
if (amount < 0) throw new IllegalArgumentException("Amount cannot be negative");
|
||||
if (balance < amount) throw new IllegalArgumentException("insufficient balance");
|
||||
balance -= amount;
|
||||
}
|
||||
finally {
|
||||
@@ -61,6 +64,8 @@ public class BankAccount {
|
||||
try {
|
||||
second.lock.writeLock().lock();
|
||||
try {
|
||||
if (amount < 0) throw new IllegalArgumentException("Amount cannot be negative");
|
||||
if (amount > balance) throw new IllegalArgumentException("insufficient balance");
|
||||
this.balance -= amount;
|
||||
target.balance += amount;
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user