protected class CQueue {
private List m_oQueue = new LinkedList(); public synchronized CItem getRequest() {
while(m_oQueue.size()==0) {
try {
printLog("before wait");
this.wait();
printLog("after wait");
}
catch(InterruptedException ie) {
printLog("InterruptedException after wait");
return null;
}
}
return (CItem)m_oQueue.remove(0);
} public synchronized void putRequest(CItem request) {
try
{
printLog("putRequest");
m_oQueue.add(request);
this.notifyAll();
printLog("after notifyAll");
}
catch(Exception ie) {
printLog("putRequest Exception");
}
}
}
下面是调用代码
CQueue m_oQueue;
while(!m_bStopped)
{
oItem= (CItem)m_oQueue.getRequest();
...
}
正常的日志,应该是2006-7-19 11:17:41 before wait
2006-7-19 11:17:42 putRequest
2006-7-19 11:17:42 after notifyAll
2006-7-19 11:17:42 after wait
但过段时间以后就变成了,
2006-7-19 11:17:42 putRequest
2006-7-19 11:17:42 after notifyAll
2006-7-19 11:17:42 before wait//这段后面就没有了after wait,好像一直在this.wait()
2006-7-19 11:17:42 putRequest
2006-7-19 11:17:42 after notifyAll
2006-7-19 11:17:42 putRequest
2006-7-19 11:17:42 after notifyAll
2006-7-19 11:17:45 putRequest
2006-7-19 11:17:45 after notifyAll