‘{〖死锁〗}’:t1 线程和[t2〖线程各〗自占有共享资 源[o1,o2,「相互在守」候对方释放资 源[,〖这样形〗成的两个线程相<互守候>,“无”法继续运行的"‘{〖死锁〗}’"《状态》.
<解决方案>:『同一个代码《‘‘(块)’’》』,〖不能持有两〗个工具锁.

package DeadLock;

public class DeadLockUse {
public static void main(String[] args) {
    Object o1 = new Object();
    Object o2 = new Object();
    Thread t1 = new MyThread1(o1,o2);
    Thread t2 = new MyThread2(o1,o2);
    t1.start();
    t2.start();
}
}
class MyThread1 extends Thread{
    Object o1;
    Object o2;
    public MyThread1(Object o1, Object o2) {
        this.o1 = o1;
        this.o2 = o2;
    }
    public void run() {
        synchronized(o1) {
            try {
                Thread.sleep(1000*3);
            } catch (InterruptedException e) {
                // TODO 〖<『(自动天生的)』>〗 catch 《‘‘(块)’’》
                e.printStackTrace();
            }
            synchronized(o2) {
                    System.out.println("‘{〖死锁〗}’解决了1!");
            }
        }
    }
}
class MyThread2 extends Thread{
    Object o1;
    Object o2;
    public MyThread2(Object o1, Object o2) {
        this.o1 = o1;
        this.o2 = o2;
    }
    public void run() {
        synchronized(o2) {
            try {
                Thread.sleep(3*1000);
            } catch (InterruptedException e) {
                // TODO 〖<『(自动天生的)』>〗 catch 《‘‘(块)’’》
                e.printStackTrace();
            }
            synchronized(o1) {
                System.out.println("‘{〖死锁〗}’解决了2!");
            }
        }
    }
}

【解】决方法:

package DeadLock;

public class DeadLockUse {
public static void main(String[] args) {
    Object o1 = new Object();
    Object o2 = new Object();
    Thread t1 = new MyThread1(o1,o2);
    Thread t2 = new MyThread2(o1,o2);
    t1.start();
    t2.start();
}
}
class MyThread1 extends Thread{
    Object o1;
    Object o2;
    public MyThread1(Object o1, Object o2) {
        this.o1 = o1;
        this.o2 = o2;
    }
    public void run() {
        synchronized(o1) {
            try {
                Thread.sleep(1000*3);
            } catch (InterruptedException e) {
                // TODO 〖<『(自动天生的)』>〗 catch 《‘‘(块)’’》
                e.printStackTrace();
            }
        }
        synchronized(o2) {
            System.out.println("‘{〖死锁〗}’解决了1!");
    }
    }
}
class MyThread2 extends Thread{
    Object o1;
    Object o2;
    public MyThread2(Object o1, Object o2) {
        this.o1 = o1;
        this.o2 = o2;
    }
    public void run() {
        synchronized(o2) {
            try {
                Thread.sleep(3*1000);
            } catch (InterruptedException e) {
                // TODO 〖<『(自动天生的)』>〗 catch 《‘‘(块)’’》
                e.printStackTrace();
            }
        }
        synchronized(o1) {
            System.out.println("‘{〖死锁〗}’解决了2!");
        }
    }
}

『运行效果』