class Called { void calling(String msg) { System.out.print("<" + msg); try { Thread.sleep(2000); } catch (InterruptedException e) { System.out.println("Interrupted "+e); } System.out.print(">"); } } class Caller implements Runnable { String msg; Called target; Thread t; public Caller(Called targ, String s) { target = targ; msg = s; t = new Thread(this); t.start(); } public void run() { synchronized (target) { target.calling(msg); } } } class SynchBlock { public static void main(String args[]) { Called target = new Called(); Caller ob1 = new Caller(target, "First"); Caller ob2 = new Caller(target, "Second"); Caller ob3 = new Caller(target, "Third"); try { ob1.t.join(); ob2.t.join(); ob3.t.join(); } catch (InterruptedException e) { System.out.println("Interrupted "+e); } } }