本地模拟死锁环境
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();
}
}
-
idea可以查看线程状态
-
jstack定位
-
jconsole