本地模擬死鎖環(huán)境
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的頭發(fā)");
}
}
}).start();
new Thread(()->{
synchronized (HAIR_B) {
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
synchronized (HAIR_A){
System.out.println("B抓住了A的頭發(fā)");
}
}
}).start();
}
}
-
idea可以查看線程狀態(tài)
-
jstack定位
-
jconsole