class MyLock { public static Object myLockA = new Object(); public static Object myLockB = new Object(); } class DieLock implements Runnable { private boolean flag = false; public void run() { if(flag) { synchronized(MyLock.myLockA) { sop("if lockA"); synchronized(MyLock.myLockB) { sop("if lockB") } } } else { synchronized(MyLock.myLockB) { sop("if lockB"); synchronized(MyLock.myLockA) { sop("if lockA") } } } } }
同学们这是看的一个死锁问题,但是他们之间怎么形成死锁的。求讲解一下 |