package thread;
public class Tickets implements Runnable{
private int ticket=100;
public void run(){
yunxing();
}
public void yunxing(){
while(ticket>1){
synchronized(this){
System.out.println(Thread.currentThread().getName()+" Sell the number "+ticket--);
try{
Thread.sleep(10);
}catch(InterruptedException e){
throw new RuntimeException(e);
}
}}
}
public static void main(String[] args){
Tickets t=new Tickets();
Thread t1=new Thread(t);
Thread t2=new Thread(t);
t1.setName("Thread1");
t2.setName("Thread2");
t1.start();
t2.start();
}
}