线程问题
我是刚学JAVA的,为什么下边的线程在运行时,两个线程卖的票都是各卖各的呀,不是一起在卖,我用的同一个对象ticket呀。为什么???请各位高手帮一下,谢谢了。public class TicketTest
{
public static void main(String[] args)
{
Ticket ticket=new Ticket();
new Thread(ticket).start();
new Thread(ticket).start();
}
}
class Ticket implements Runnable
{
public void run()
{
int ticketNumber=100;
while(true)
{
if(ticketNumber>0)
{
System.out.println(Thread.currentThread().getName()+" :"+
ticketNumber);
ticketNumber--;
}
}
}
}