HER-2065 - in activateInactiveQueue() close synchronized block earlier, and move updateHighestWaiting() up to keep it inside the block; now the call to deactivateQueue() is not in the synchronized block, so the deadlock should be avoided (fix suggested by kenji)

This commit is contained in:
Noah Levitt
2014-04-24 17:23:01 -07:00
parent 3a456638ca
commit d777c198bd
@@ -764,32 +764,33 @@ implements Closeable,
Queue<String> queueOfWorkQueueKeys = entry.getValue();
while (true) {
String workQueueKey;
synchronized (getInactiveQueuesByPrecedence()) {
String workQueueKey = queueOfWorkQueueKeys.poll();
workQueueKey = queueOfWorkQueueKeys.poll();
if (workQueueKey == null) {
break;
}
WorkQueue candidateQ = (WorkQueue) this.allQueues.get(workQueueKey);
if (candidateQ.getPrecedence() > expectedPrecedence) {
// queue demoted since placed; re-deactivate
deactivateQueue(candidateQ);
candidateQ.makeDirty();
continue;
}
updateHighestWaiting(expectedPrecedence);
try {
readyClassQueues.put(workQueueKey);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return true;
}
WorkQueue candidateQ = (WorkQueue) this.allQueues.get(workQueueKey);
if (candidateQ.getPrecedence() > expectedPrecedence) {
// queue demoted since placed; re-deactivate
deactivateQueue(candidateQ);
candidateQ.makeDirty();
continue;
}
try {
readyClassQueues.put(workQueueKey);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return true;
}
}
return false;
}