启动了四个线程,为什么只执行了一个
运行结果只有携程卖票,其他的线程却不卖,请问是为什么class MyRunnable implements Runnable{
private Integer ticketscount=1000;
@Override
public void run() {
synchronized(this){
while(ticketscount>0){
System.out.println(Thread.currentThread().getName()+"卖出了一张票,还剩"+--ticketscount+"张票");
}
}
}
}
public class TicketsRunnable{
public static void main(String [] args){
MyRunnable mr=new MyRunnable();
Thread th1=new Thread(mr,"携程");
Thread th2=new Thread(mr,"途牛");
Thread th3=new Thread(mr,"12306");
Thread th4=new Thread(mr,"手机客户端");
th1.start();
th2.start();
th3.start();
th4.start();
}
}