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