class TicketDemo
{
public static void main(String[] args)
{
Ticket t1 = new Ticket();
Ticket t2 = new Ticket();
Ticket t3 = new Ticket();
Ticket t4 = new Ticket();
t1.start();
t2.start();
t3.start();
t4.start();
}
}
class Ticket extends Thread
{
private static int tick = 40;
public void run()
{
while(tick>0)
{
System.out.println(currentThread().getName()+"sale :"+tick--);//代码1:这里做自减动作,运行结果正常:40 39 38 37 ...
//tick--;//代码2:假如上一条输出语句不做自减动作,这里再自减,结果会打印4个40,然后才打印39 38 37 36 ... 也就是多打印了3个40
}
}
}
有大神能解释一下吗? |
|