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