案例
public class DeadLockExe {
public static void main(String[] args) {
Object lock1 = new Object();
Object lock2 = new Object();
new Thread(() -> {
synchronized(lock1) {
System.out.println("thread A get lock1");
try {
Thread.sleep(100);
} catch(Exception e) {
e.printStackTrace();
}
synchronized(lock2) {
System.out.println("thread A get lock2");
}
}
}).start();
new Thread(() -> {
synchronized(lock2) {
System.out.println("thread B get lock2");
try {
Thread.sleep(100);
} catch(Exception e) {
e.printStackTrace();
}
synchronized(lock1) {
System.out.println("thread B get lock1");
}
}
}).start();
}
}
排查
1. Terminal命令行排查
jps -l
获取进程编号
jstack 进程编号
排查(这里是12888)
2. 图形化界面排查
CMD: jconsole