public static void transfer BankAccount from BankAccount to int amount

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
public static void transfer(BankAccount from, BankAccount to, int amount) {
try {
if (from.lock.tryLock(10000, TimeUnit.MILLISECONDS)){
//Thread.sleep(100);
if (to.lock.tryLock(1000, TimeUnit.MILLISECONDS)) {
System.out.println("Transfering from " + from.id + " account to " + to.id + " one");
from.withdraw(amount);
to.deposit(amount);
System.out.println(from.id + " account balance: " + from.currentBalance);
System.out.println(to.id + " account balance: " + to.currentBalance);
}
}
} catch (InsufficientFundsException e) {
System.out.println("You have not enough money on deposit account");
} catch (InterruptedException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
finally {
}
}