class Ticket implements Runnable
{
private boolean bl;
private int set=100;
Ticket(boolean bl)
{
this.bl=bl;
}
public void run()
{
if (bl==true)
{
synchronized(Rl.obj)
{
System.out.println("Ticket ="+set--);
synchronized(Rl.obj1)
{
System.out.println("Ticket 2="+set--);
}
}
}
else
synchronized(Rl.obj1)
{
System.out.println("else ="+set--);
synchronized(Rl.obj)
{
System.out.println("else 12 ="+set--);
}
}
}
}
class Rl
{
static Object obj=new Object();
static Object obj1=new Object();
}
class Wime
{
public static void main(String[] args)
{
Thread t=new Thread(new Ticket(true));
Thread t1=new Thread(new Ticket(false));
}
}
|
|