多线程|死锁

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");
}
}
}
};

}
}

 

 

 

posted @ 2023-08-28 17:56  司丝思  阅读(15)  评论(0)    收藏  举报