class TicketTest
{
public static void main(String[] arg)
{
SellT st=new SellT();
new Thread(st).start();
new Thread(st).start();
new Thread(st).start();
new Thread(st).start();
}
}
class SellT implements Runnable
{
int tickets=100;
Object obj=new Object();
public void run()
{
while(true)
{
sell();
}
}
public synchronized void sell()
{
if(tickets>0)
{
try
{
Thread.sleep(10);
}
catch(Exception e)
{
}
System.out.println(Thread.currentThread().getName()+"线程卖出第:"+tickets+"张票");
tickets--;
}
}
}