死锁的排查方法

本地模拟死锁环境

package com.fandf.thread.lock;

/**
 * @author fandongfeng
 * @created 2019/12/20 13:20
 * @description 死锁
 */
public class DeadLockDemo {

    private static final Object HAIR_A = new Object();

    private static final Object HAIR_B = new Object();


    public static void main(String[] args) {

        new Thread(()->{
            synchronized (HAIR_A) {
                try {
                    Thread.sleep(50);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (HAIR_B){
                    System.out.println("A抓住了B的头发");
                }
            }
        }).start();

        new Thread(()->{
            synchronized (HAIR_B) {
                try {
                    Thread.sleep(50);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (HAIR_A){
                    System.out.println("B抓住了A的头发");
                }
            }
        }).start();

    }

}
  1. idea可以查看线程状态


    image.png
  2. jstack定位


    image.png

    image.png
  3. jconsole


    image.png

    image.png

    image.png

    image.png

    image.png

你可能感兴趣的:(死锁的排查方法)