class TickCheck{
public static void main(String[] args){
SellThread x=new SellThread();
new Thread(x).start();
try{ Thread.sleep(1);}catch(InterruptedException e){}
x.b=true;
new Thread(x).start();
}
}
class SellThread implements Runnable{
int ticket=1000;
Object o=new Object();
boolean b=false;
public void run(){
if (b)
sell();
else{
synchronized(this){
while(ticket>0){
System.out.println(Thread.currentThread().getName()+" "+ticket);
ticket--;
}
}
}
}
public synchronized void sell(){
while(ticket>0){
System.out.println("sell:"+Thread.currentThread().getName()+" "+ticket);
ticket--;
}
}