package edu.nyu.cs9053.concurrency.chapter14.bank;

/**
 * User: blangel
 * Date: 7/26/14
 * Time: 11:00 AM
 */
public class Bank {

    public void transfer(Account from, Account to, int amount) {
        synchronized (from) {
            synchronized (to) {
                System.out.printf("Transferring %d from %s to %s%n", amount, from.getName(), to.getName());
                from.decrement(amount); // first decrement, ensuring the funds are available
                to.increment(amount);
            }
        }
    }

}
