public class DeadlockDebuggee extends Thread {
    
    private Object o1 = new Object();
    private Object o2 = new Object();
    
    private boolean ready1 = false;
    private boolean ready2 = false;
    
    class SecondThread extends Thread {

        public SecondThread() {
            setName("Second thread");
        }
        
        public void run() {
			System.err.println("started 2");
            synchronized (o1) {
                
                ready1 = true;
                
                while (!ready2) {
                    Thread.yield();
                }

                synchronized (o2) {
                    System.err.println("Should not be here");
                }                
            }
        }
    }
    
    public void run() {
		System.err.println("started 1");
        SecondThread t2 = new SecondThread();
        t2.start();
        synchronized (o2) {
            
            ready2 = true;
            
            while (!ready1) {
                Thread.yield();
            }

            synchronized (o1) {
                System.err.println("Should not be here");
            }                
        }        
    }
    
    public static void main(String[] args) throws Exception {
	   DeadlockDebuggee d = new DeadlockDebuggee();
	   d.run();
	   d.new SecondThread().start();
    }
}
