put函数的括号位置错了,所以一直在wait,不往下走.
把notify后面的括号提到seq=value前面就可以了。
如下public synchronized void put(int value)
{
while (available == true)
{
try
{
wait(); // waits for notify() call from consumer
}
catch (InterruptedException e)
{ }
}
seq = value;
available = true;
notify();
}
把notify后面的括号提到seq=value前面就可以了。
如下public synchronized void put(int value)
{
while (available == true)
{
try
{
wait(); // waits for notify() call from consumer
}
catch (InterruptedException e)
{ }
}
seq = value;
available = true;
notify();
}
public synchronized void put(int value) {
while (available == true) {
try {
wait(); // waits for notify() call from consumer
} catch (InterruptedException e) { }
}
seq = value;
available = true;
notify();
}