solved Task AccountTransfer
This commit is contained in:
parent
7dfa09a53e
commit
ac876c7979
|
@ -13,11 +13,11 @@ public class Account {
|
|||
return id;
|
||||
}
|
||||
|
||||
public int getBalance() {
|
||||
public synchronized int getBalance() {
|
||||
return balance;
|
||||
}
|
||||
|
||||
public void transferAmount(int amount) {
|
||||
public synchronized void transferAmount(int amount) {
|
||||
this.balance += amount;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,8 @@ public class AccountTransferSimulation {
|
|||
(account1.getBalance() + account2.getBalance() + account3.getBalance()));
|
||||
System.out.println("Start of Transaction");
|
||||
|
||||
AccountTransferTask task1 = new AccountTransferTask(account3, account1, 2);
|
||||
AccountTransferTask task1 = new AccountTransferTask(account1, account3, 2);
|
||||
//AccountTransferTask task1 = new AccountTransferTask(account3, account1, 2);
|
||||
AccountTransferTask task2 = new AccountTransferTask(account3, account2, 1);
|
||||
AccountTransferTask task3 = new AccountTransferTask(account2, account1, 2);
|
||||
|
||||
|
|
Loading…
Reference in New Issue