Skip to content

Commit

Permalink
Doing something with boolean returned by await method (#68)
Browse files Browse the repository at this point in the history
Sonar indicated this as a bug. It's not really the way we're using it: we don't really care if there was a signal or if the wait time is over, we act the same anyway. But for debugging purposes it might be nice to log this, so added this information as a trace.
  • Loading branch information
BertScholten authored Dec 5, 2023
1 parent 6d8a037 commit 0ee3c2c
Showing 1 changed file with 15 additions and 8 deletions.
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

0 comments on commit 0ee3c2c

Please sign in to comment.