class Ticket implements Runnable
{
private int num = 200;
public void run()
{
while(true)
{
synchronized(new Object())
{
if(num > 0)
{
try
{
Thread.sleep(20);
}
catch (InterruptedException e)
{
}
System.out.println(Thread.currentThread().getName()+"....sale...."+num--);
}
else
break;
}
}
}
}
class TicketDemo
{
public static void main(String[] args)
{
Ticket t = new Ticket();
Thread t1 = new Thread(t);
Thread t2 = new Thread(t);
Thread t3 = new Thread(t);
Thread t4 = new Thread(t);