Remove unneeded calls to hasScheduledTasks() when fetching from scheduled task queue for event executors.
Motivation: Currently in the single threaded and global event executors when the scheduled task queue is drained, there is a call to hasScheduledTasks(). If there are scheduled tasks then the the code polls the queue for tasks. The poll method duplicates the exact logic of hasScheduledTasks(). This involves two calls to nanoTime when one seems sufficient. Modifications: Directly poll the queue for tasks and break if the task returned is null. Result: Should be no noticeable impact on functionality. Two calls to nanoTime have been coarsened into a single call.
This commit is contained in:
parent
4676a2271c
commit
181c159c24
@ -104,15 +104,11 @@ public final class GlobalEventExecutor extends AbstractScheduledEventExecutor {
|
||||
}
|
||||
|
||||
private void fetchFromScheduledTaskQueue() {
|
||||
if (hasScheduledTasks()) {
|
||||
long nanoTime = AbstractScheduledEventExecutor.nanoTime();
|
||||
for (;;) {
|
||||
Runnable scheduledTask = pollScheduledTask(nanoTime);
|
||||
if (scheduledTask == null) {
|
||||
break;
|
||||
}
|
||||
taskQueue.add(scheduledTask);
|
||||
}
|
||||
long nanoTime = AbstractScheduledEventExecutor.nanoTime();
|
||||
Runnable scheduledTask = pollScheduledTask(nanoTime);
|
||||
while (scheduledTask != null) {
|
||||
taskQueue.add(scheduledTask);
|
||||
scheduledTask = pollScheduledTask(nanoTime);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -276,19 +276,15 @@ public abstract class SingleThreadEventExecutor extends AbstractScheduledEventEx
|
||||
}
|
||||
|
||||
private boolean fetchFromScheduledTaskQueue() {
|
||||
if (hasScheduledTasks()) {
|
||||
long nanoTime = AbstractScheduledEventExecutor.nanoTime();
|
||||
for (;;) {
|
||||
Runnable scheduledTask = pollScheduledTask(nanoTime);
|
||||
if (scheduledTask == null) {
|
||||
break;
|
||||
}
|
||||
if (!taskQueue.offer(scheduledTask)) {
|
||||
// No space left in the task queue add it back to the scheduledTaskQueue so we pick it up again.
|
||||
scheduledTaskQueue().add((ScheduledFutureTask<?>) scheduledTask);
|
||||
return false;
|
||||
}
|
||||
long nanoTime = AbstractScheduledEventExecutor.nanoTime();
|
||||
Runnable scheduledTask = pollScheduledTask(nanoTime);
|
||||
while (scheduledTask != null) {
|
||||
if (!taskQueue.offer(scheduledTask)) {
|
||||
// No space left in the task queue add it back to the scheduledTaskQueue so we pick it up again.
|
||||
scheduledTaskQueue().add((ScheduledFutureTask<?>) scheduledTask);
|
||||
return false;
|
||||
}
|
||||
scheduledTask = pollScheduledTask(nanoTime);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user