public class DeadLock {
public static void main(String[] args) {
Object g =new Object();
Object m =new Object();
//访问同一个货物资源
new Goods(m,g).start();
}
}
class Goods extends Thread{
private Object goods =new Object();
private Object money =new Object();
public Goods(){
}
public Goods(Object goods,Object money){
super();
this.goods =goods;
this.money =money;
}
public void run() // 这里为什么不能直接throws呢???
{
synchronized (goods) {
try {
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
class Mondy extends Thread{
} |