为何出现
public static void main(String[] args) {
Object a = new Object() ;
Object b = new Object();
new Thread(() -> {
synchronized (a){
System.out.println(Thread.currentThread().getName() + "get a" + a);
synchronized (b){
System.out.println(Thread.currentThread().getName() + "get b" + b);
}
}
}).start();
new Thread(() -> {
synchronized (b){
System.out.println(Thread.currentThread().getName() + "get b" + b);
synchronized (a){
System.out.println(Thread.currentThread().getName() + "get a" + a);
}
}
}).start();
}
jps 和 jstack 工具查看死锁
如何解决