死锁

  1. jdk自带命令行工具:jsp + jstack -l pid
  2. jdk自带可视化工具:jvisualvm
  3. jdk自带可视化工具:jconsole

public class T {

    public static void main(String[] args) throws InterruptedException {
        Object lock1 = new Object();
        Object lock2 = new Object();

        new Thread(() -> {
            try {
                synchronized (lock1) {
                    Thread.sleep(200);
                    synchronized (lock2) {

                    }
                }
            } catch (Exception e) {

            }
        }, "线程1").start();

        new Thread(() -> {
            try {
                synchronized (lock2) {
                    Thread.sleep(200);
                    synchronized (lock1) {

                    }
                }
            } catch (Exception e) {

            }
        }, "线程2").start();
    }
}

posted @ 2024-08-15 11:03  干饭达人GoodLucy  阅读(3)  评论(0编辑  收藏  举报