死锁
- jdk自带命令行工具:jsp + jstack -l pid
- jdk自带可视化工具:jvisualvm
- 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();
}
}