This dequeue method still seems fishy to me, even after your fix (not
that your fix broke anything that wasn't already broken). Shouldn't
there by a while (resource == null) instead of just an if?
public synchronized Object dequeue(long aTimeout) {
Object resource = dequeue();
if (resource == null && cpm.isRunning()) {
try {
if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST,
this.getClass().getName(),
"process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
"UIMA_CPM_queue_empty__FINEST",
new Object[] { Thread.currentThread().getName(), queueName });
}
this.wait(aTimeout);
} catch (InterruptedException e) {
}
if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
UIMAFramework.getLogger(this.getClass()).logrb(
Level.FINEST,
this.getClass().getName(),
"process",
CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
"UIMA_CPM_queue_notified__FINEST",
new Object[] { Thread.currentThread().getName(), queueName,
String.valueOf(numberElementsInQueue) });
}
resource = dequeue();
}
return resource;
}
If multiple threads can be in the wait, they will all be notified when
a new object is added to the queue. But dequeue() might succeed only
for one of them, the other would return null, without having waited
for its full timeout.
-Adam