public class ExampleFour {
    private static int x = 0;
    private static Object y = new Object();
    public static void main(String args[]) throws InterruptedException {
	Runnable r1 = new Runnable () {
		public void run() { 
		    x = 1;
		    synchronized (y) { }
		}
	    };
	Runnable r2 = new Runnable () {
		public void run() { 
		    synchronized (y) { }
		    System.out.println(x);
		}
	    };
	Thread t1 = new Thread(r1);
	Thread t2 = new Thread(r2);
	t1.start();
	t2.start();
    }
}