Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doing something with boolean returned by await method #68

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -106,26 +106,33 @@ public Task getNextTask() throws InterruptedException {
final String queueName = task.getTaskConsumer().getQueueName();
taskPresent = isTaskNext(queueName);
if (taskPresent) {
tasksOnWorkers++;
tasksOnWorkersPerQueue.get(queueName).incrementAndGet();
task = queue.poll();
if (task.getContext() != null) {
task.getContext().makeCurrent();
}
obtainTask(queueName);
}
}
// If no task present, await till we get a signal that there could be a new one (or a max time to avoid 'deadlocks')
if (!taskPresent) {
nextTaskCondition.await(NEXT_TASK_MAX_WAIT_TIME_SECONDS, TimeUnit.SECONDS);
final boolean receivedSignal = nextTaskCondition.await(NEXT_TASK_MAX_WAIT_TIME_SECONDS, TimeUnit.SECONDS);
if (!receivedSignal) {
LOG.trace("Waited long enough for next task, trying again");
}
}

} while (!taskPresent);
} finally {
lock.unlock();
}
return task;
}

private Task obtainTask(final String queueName) {
tasksOnWorkers++;
tasksOnWorkersPerQueue.get(queueName).incrementAndGet();
final Task task = queue.poll();
if (task.getContext() != null) {
task.getContext().makeCurrent();
}
return task;
}

/**
* Last check to avoid the queue is clogged with slow processes. The following conditions are checked:
* <ul>
Expand Down
Loading