Skip to content

Commit 81c54a8

Browse files
committed
Inline TimedRunnable.beforeExecute
No need to call the method separately as it can be invoked the first time getQueueTimeNanos is called. Relates: #120488
1 parent 696716c commit 81c54a8

File tree

2 files changed

+1
-10
lines changed

2 files changed

+1
-10
lines changed

server/src/main/java/org/elasticsearch/common/util/concurrent/TaskExecutionTimeTrackingEsThreadPoolExecutor.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ protected void beforeExecute(Thread t, Runnable r) {
163163
}
164164
assert super.unwrap(r) instanceof TimedRunnable : "expected only TimedRunnables in queue";
165165
final TimedRunnable timedRunnable = (TimedRunnable) super.unwrap(r);
166-
timedRunnable.beforeExecute();
167166
final long taskQueueLatency = timedRunnable.getQueueTimeNanos();
168167
assert taskQueueLatency >= 0;
169168
queueLatencyMillisHistogram.addObservation(TimeUnit.NANOSECONDS.toMillis(taskQueueLatency));

server/src/main/java/org/elasticsearch/common/util/concurrent/TimedRunnable.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ public boolean isForceExecution() {
6666
*/
6767
long getQueueTimeNanos() {
6868
if (beforeExecuteTime == -1) {
69-
assert false : "beforeExecute must be called before getQueueTimeNanos";
70-
return -1;
69+
beforeExecuteTime = System.nanoTime();
7170
}
7271
return beforeExecuteTime - creationTimeNanos;
7372
}
@@ -84,13 +83,6 @@ long getTotalExecutionNanos() {
8483
return Math.max(finishTimeNanos - startTimeNanos, 1);
8584
}
8685

87-
/**
88-
* Called when the task has reached the front of the queue and is about to be executed
89-
*/
90-
public void beforeExecute() {
91-
beforeExecuteTime = System.nanoTime();
92-
}
93-
9486
/**
9587
* If the task was failed or rejected, return true.
9688
* Otherwise, false.

0 commit comments

Comments
 (0)