多线程|死锁

xbyss / 2023-08-28 / 原文

public class ThreadDemo19 {
private static Object o1 = new Object();
private static Object o2 = new Object();
public static void main(String[] args) {
Thread t1 = new Thread(){
public void run(){
synchronized (o1){
System.out.println(getName() + "====o1");
synchronized (o2){
System.out.println(getName() + "====o2");
}
}
}
};
Thread t2 = new Thread(){
public void run(){
synchronized (o2){
System.out.println(getName() + "====o2");
synchronized (o1){
System.out.println(getName() + "====o1");
}
}
}
};

}
}