public class SaleShare implements Runnable{
	private int shares = 20;
	public void run(){
		while(true){
			if(shares > 0){//只允许票号大于0.
				try{
					Thread.sleep(300);//睡眠0.3秒.
				}catch(InterruptedException e){
					e.printStackTrace();
				}
				System.out.println(
						Thread.currentThread().getName()+
						" 销售票号 "+shares--);
			}else{
				break;
			}
		}
	}

	public static void main(String[] args){
		SaleShare obj = new SaleShare();
		//下面3个线程共享 obj 对象.
		new Thread(obj,"A").start();//命名当前线程为A
		new Thread(obj,"B").start();
		new Thread(obj,"C").start();
	}
}
