package com.pcs;
public class TicketDemo{
public static void main(String[] args){
Demo d=new Demo();
for(int i=0;i<5;i++)
new Thread(d,"售票口 "+(i+1)+" :").start();
}
}
class Demo implements Runnable{
private volatile int num=100;
public void run(){
while(num>0){
synchronized(this){
try{
Thread.sleep(100);
}catch(Exception e){}
if(num>0){
System.out.println(Thread.currentThread().getName()+num);
num--;
}
}
}
}
}