publicclassTestDeadLock{privatestaticString a ="A";privatestaticString b ="B";publicstaticvoid deadLock (){Thread threadA =newThread(newRunnable(){@Overridepublicvoidrun(){synchronized(a){System.out.println("threadA get a");synchronized(b){System.out.println("threadA get b");}}}});Thread threadB =newThread(newRunnable(){@Overridepublicvoidrun(){synchronized(b){System.out.println("threadB get b");synchronized(a){System.out.println("threadB get a");}}}});
threadA.start();
threadB.start();}publicstaticvoidmain(String[] args){deadLock();}}