public class DeadLock { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub final Object resource1 = "resource1"; final Object resource2 = "resource2"; Thread t1 = new Thread(){ public void run(){ synchronized(resource1){ System.out.println("Thread1:locked resource1"); try{ Thread.sleep(50); }catch(Exception ex){ } synchronized(resource2){ System.out.println("Thread1:locked resource2"); } } } }; Thread t2 = new Thread(){ public void run(){ synchronized(resource2){ System.out.println("Thread2:locked resource2"); try{ Thread.sleep(50); }catch(Exception ex){ } synchronized(resource1){ System.out.println("Thread2:locked resource1"); } } } }; t1.start(); t2.start(); } }