我出现了楼上的情况后改了代码: public void run() {
while(number>0){
System.out.println(Thread.currentThread().getName()+"卖出一张票,还剩"+(--number));
}
} 但最后输出结果仍然没变 什么鬼 输出:
商店2卖出一张票,还剩4
商店3卖出一张票,还剩3
商店1卖出一张票,还剩4
商店3卖出一张票,还剩1
商店2卖出一张票,还剩2
商店1卖出一张票,还剩0
你没有加同步块吧?synchroized