黑马程序员-多线程死锁

来源:互联网 发布:焊接仿真软件 编辑:程序博客网 时间:2024/05/21 20:14

---------------------- <a href="http://www.itheima.com"target="blank">ASP.Net+Unity开发</a>、<a href="http://www.itheima.com"target="blank">.Net培训</a>、期待与您交流! ----------------------

package 多线程;

class Dead implements Runnable{
private boolean flag;
Dead(boolean f){
flag=f;
}
}
else{
synchronized(MyLock.mylockb){
System.out.println("MyLock.mylockb");
synchronized(MyLock.mylocka){
System.out.println("MyLock.mylocka");
}
}
}
}
}
class MyLock{
public static Object mylocka=new Object();
public static Object mylockb=new Object();
}
public class DeadLockDemo{
public static void main(String[] args){
Thread t1=new Thread(new Dead(true));
Thread t2=new Thread(new Dead(false));

t1.start();
t2.start();
}
}

死锁出现的问题是由于俩个线程互相站着对方的锁,使双方都不能继续运行下去

---------------------- <a href="http://www.itheima.com"target="blank">ASP.Net+Unity开发</a>、<a href="http://www.itheima.com"target="blank">.Net培训</a>、期待与您交流! ----------------------


详细请查看:<a href="http://www.itheima.com" target="blank">www.itheima.com</a>



0 0