小测试,如何实现变量ticket的同步
private int ticket = 100;
public void run()
{
while(ticket > 0 ) {
System.out.println(ticket+" is saled by "+
Thread.currentThread().getName());
ticket--;
try
{
Thread.sleep(200);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
}