/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		final Ideone one = new Ideone();
		Thread t = new Thread (new Runnable(){
			public void run(){
				int i = 0;
				while(i < 100) {
			    	try {
				      one.methodB();
				    } catch(Throwable e){System.out.println(e);}
				    System.out.println("methodB called!");
				    i++;
				}
				
			}
		});
		t.start();
		
		try{
			one.sync = new Object();
			t.join();
		}catch(Throwable e){System.out.println(e);}
		finally{
			System.out.println("Done");
		}
	}
private Object sync = new Object();
public void methodA() throws InterruptedException {
    synchronized(this.sync){
    	Thread.sleep(1000);
    }
}
public void methodB() throws InterruptedException {
    synchronized(this.sync){
		    methodA();
    }
}   
}