简单的锁顺序死锁(不要这么做)

public class LeftRightDeadLock
{
    private final Object left = new Object();
   
    private final Object right = new Object();
   
    public void leftRight()
    {
        synchronized (left)
        {
            synchronized (right)
            {
                //doSomthing();  
            }
        }
    }
   
    public void rightLeft()
    {
        synchronized (right)
        {
            synchronized (left)
            {
                //doSomething();  
            }
        }
    }
}

你可能感兴趣的:(简单的锁顺序死锁(不要这么做))