package edu.nyu.cs9053.concurrency.deadlock;

/**
 * User: blangel
 * Date: 11/9/14
 * Time: 11:28 AM
 */
public class Walker {

    private final Object first;

    private final Object second;

    public Walker(Object first, Object second) {
        this.first = first;
        this.second = second;
    }

    public boolean attemptPass() {
        System.out.printf("Trying %s...%n", first.toString());
        synchronized (first) {
            System.out.printf("Trying %s...%n", second.toString());
            synchronized (second) {
                return true;
            }
        }
    }

}
