线程同步
按步就班抄的.但是效果就是不对.
各位大大帮忙看下哪错了
public class Xiancheng
{
public static void main(String args[])
{
A t=new A();
new Thread(t).start();
new Thread(t).start();
new Thread(t).start();
new Thread(t).start();
}
}
class A implements Runnable
{
int p=100;
public void run()
{
while(true)
{
sell();
}
}
public synchronized void sell()
{
if(p>0)
{
System.out.println(Thread.currentThread().getName()+p);
p--;
}
}
}