solved Task AccountTransfer

This commit is contained in:
romanschenk37 2022-04-07 14:37:54 +02:00
parent 7dfa09a53e
commit ac876c7979
2 changed files with 4 additions and 3 deletions

View File

@ -13,11 +13,11 @@ public class Account {
return id; return id;
} }
public int getBalance() { public synchronized int getBalance() {
return balance; return balance;
} }
public void transferAmount(int amount) { public synchronized void transferAmount(int amount) {
this.balance += amount; this.balance += amount;
} }
} }

View File

@ -22,7 +22,8 @@ public class AccountTransferSimulation {
(account1.getBalance() + account2.getBalance() + account3.getBalance())); (account1.getBalance() + account2.getBalance() + account3.getBalance()));
System.out.println("Start of Transaction"); 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 task2 = new AccountTransferTask(account3, account2, 1);
AccountTransferTask task3 = new AccountTransferTask(account2, account1, 2); AccountTransferTask task3 = new AccountTransferTask(account2, account1, 2);