多线程|死锁


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




                    
                
                
            
        
浙公网安备 33010602011771号