java中死锁有很多种情况,这里简单列一下顺序性死锁
public static Object o1 = new Object();
public static Object o2 = new Object();
public static void main(String[] args) {
new Thread(new Runnable() {
@Override
public void run() {
try {
synchronized (IndexController.o2) {
///Thread.sleep(3000);
System.out.println("拿到o2");
synchronized (IndexController.o1) {
System.out.println("拿到o1");
}
}
}catch (Exception e){
}
}
}).start();
new Thread(new Test2()).start();
}
}
class Test2 implements Runnable{
@Override
public void run() {
try {
synchronized (IndexController.o1) {
System.out.println("拿到o1");
//Thread.sleep(3000);
synchronized (IndexController.o2) {
System.out.println("拿到o2");
}
}
}catch (Exception e){
}
}
}