多线程结果不对?
class TicketsSystem {
public static void main(String[] args)
{
SellThread st=new SellThread();
new Thread(st).start();
new Thread(st).start();
new Thread(st).start();
new Thread(st).start();
}
}
class SellThread implements Runnable
{
int tickets=100;
public void run()
{
while(true)
{
if(tickets>0)
{
System.out.println(Thread.currentThread().getName()+" sell tickets: "+tickets);
tickets--;
}
}
}
}
为什么结果不是按顺序的?