/**
* @description:
* @author: xz
*/
public class DeadLock implements Runnable{
private Object object1;
private Object object2;
public DeadLock(Object object1,Object object2){
this.object1 =object1;
this.object2 =object2;
}
@Override
public void run() {
synchronized (object1){
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
synchronized (object2){
System.out.println("hello world");
}
}
}
}
public class DeadLockTest {
public static void main(String[] args) {
Object obj1 = new Object();
Object obj2 = new Object();
new Thread(new DeadLock(obj1,obj2)).start();
new Thread(new DeadLock(obj2,obj1)).start();
}
}
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://wwwxz.blog.csdn.net/article/details/123024303
内容来源于网络,如有侵权,请联系作者删除!