Skip to content

Instantly share code, notes, and snippets.

@lwahlmeier
Created September 15, 2017 21:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lwahlmeier/cdd1b0d03607eda348e894893d3581c6 to your computer and use it in GitHub Desktop.
Save lwahlmeier/cdd1b0d03607eda348e894893d3581c6 to your computer and use it in GitHub Desktop.
public TaskWrapper getNextTask() {
// First compare between high and low priority task queues
// then depending on that state, we may check starvable
TaskWrapper nextTask = null;
if (lowPriorityQueueSet.isEmpty() && !highPriorityQueueSet.isEmpty()) {
nextTask = highPriorityQueueSet.getNextTask();
} else if (!lowPriorityQueueSet.isEmpty() && !highPriorityQueueSet.isEmpty()) {
if(highPriorityQueueSet.timeSinceLastPull() > maxWaitForLowPriorityInMs) {
nextTask = lowPriorityQueueSet.getNextTask();
} else {
nextTask = highPriorityQueueSet.getNextTask();
}
} else if (!lowPriorityQueueSet.isEmpty() && highPriorityQueueSet.isEmpty()) {
nextTask = lowPriorityQueueSet.getNextTask();
} else {
nextTask = starvablePriorityQueueSet.getNextTask();
}
return nextTask;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment