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();
}
}