您的位置:首页 > 编程语言 > Java开发

JAVA 死锁

2015-11-22 13:16 393 查看
class Locker

{

static Object lockerA=new Object();

static Object lockerB=new Object();

}

class CRun implements Runnable

{

boolean flag=false;

public CRun(boolean flag)

{

this.flag=flag;

}

public void run()

{

if(flag)

{

synchronized(Locker.lockerA)

{

System.out.println("True get lockerA");

synchronized(Locker.lockerB)

{

System.out.println("True get lockerB");

}

}

}

else

{

synchronized(Locker.lockerB)

{

System.out.println("False get lockerB");

synchronized(Locker.lockerA)

{

System.out.println("False get lockerA");

}

}

}

}

}

class DeadLockerTest

{

public static void main(String[] args)

{

Thread thread1=new Thread(new CRun(false));

Thread thread2=new Thread(new CRun(true));

thread1.start();

thread2.start();

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: