package com.rihui.thread;
public class TestDeadLock1 {
public static void main(String[] args) {
//定义两把钥匙
final Object O1=new Object();
final Object O2=new Object();
new Thread(new Runnable(){
@Override
public void run() {
synchronized(O1){
try {
System.out.println("放人");
Thread.sleep(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
synchronized(O2){
}
}
}
}).start();
new Thread(new Runnable(){
@Override
public void run() {
synchronized(O2){
try {
System.out.println("给钱");
Thread.sleep(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
synchronized(O1){
}
}
}
}).start();
}
}
public class TestDeadLock1 {
public static void main(String[] args) {
//定义两把钥匙
final Object O1=new Object();
final Object O2=new Object();
new Thread(new Runnable(){
@Override
public void run() {
synchronized(O1){
try {
System.out.println("放人");
Thread.sleep(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
synchronized(O2){
}
}
}
}).start();
new Thread(new Runnable(){
@Override
public void run() {
synchronized(O2){
try {
System.out.println("给钱");
Thread.sleep(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
synchronized(O1){
}
}
}
}).start();
}
}