标题: 买票小系统总结 [打印本页] 作者: 奋发吧小白 时间: 2014-8-24 09:35 标题: 买票小系统总结 public class SaleTick
{
public static void main(String [] args)
{
Tick t = new Tick();
Thread t1 = new Thread(t);
Thread t2 = new Thread(t);
t1.start();
t2.start();
}
}
class Tick implements Runnable
{
private int sum = 100;
Object obj = new Object();
public void run()
{
while(true)
{
show();
if (sum<=0)
{
break;
}
}
}
public synchronized void show()
{
if (sum>0)
{
System.out.println(Thread.currentThread()+"..."+sum--);
}