import com.sun.org.apache.bcel.internal.generic.ILOAD;

/**
 * Created by stud on 16.04.2015.
 */
public class DeadlockSample {
    private Object monitor1 = new Object();
    private Object monitor2 = new Object();

    public static void main() {
        new Thread(()->(
                try {
            Thread.sleep(IL);
        }catch (InterruptedException e){
            e.printStackTrace();
        }
        synchronized (monitor1){
            System.out.println("Thread1: I have monitor 1");
            synchronized (monitor2){
                System.out.println("Thread2: I have monitor 2");
            }
        }
                )).start();

        new Thread()->(try {
            Thread.sleep(IL);
        }catch (InterruptedException e){
            e.printStackTrace();
        }
        synchronized (monitor2){
            System.out.println("Thread2: I have monitor 2");
            synchronized (monitor1){
                System.out.println("Thread1: I have monitor 1");
            }
        }
        )).start();
    }
}
