import java.io.*;
class Test
{
public static void main (String[] args) throws java.lang.Exception
{
Ticks t1 = new Ticks(100);
Ticks t2 = new Ticks();
t1.start();
t2.start();
}
}
class Ticks extends Thread
{
private static int num;
public Ticks()
{
}
public Ticks(int num)
{
this.num = num ;
}
public int getNum()
{
return num;
}
public void run()
{
while(true)
{
shu();
}
}
public synchronized void shu()
{
if(num>0)
{
try {
Thread.sleep(100);
} catch(Exception e) {
}
System.out.println(Thread.currentThread().getName()+":卖票"+getNum());
num--;
}
}
} |
|