Skip to content

Commit

Permalink
Fix TimedRunnable log NPE (#4425)
Browse files Browse the repository at this point in the history
  • Loading branch information
AnonHxy authored Jun 10, 2024
1 parent fd2c7c6 commit 43b5ccc
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,12 @@ public T build() {
protected class TimedRunnable implements Runnable {
final Runnable runnable;
final long initNanos;
final Class<?> runnableClass;

TimedRunnable(Runnable runnable) {
this.runnable = runnable;
this.initNanos = MathUtils.nowInNano();
this.runnableClass = runnable.getClass();
}

@Override
Expand All @@ -203,8 +205,7 @@ public void run() {
long elapsedMicroSec = MathUtils.elapsedMicroSec(startNanos);
taskExecutionStats.registerSuccessfulEvent(elapsedMicroSec, TimeUnit.MICROSECONDS);
if (elapsedMicroSec >= warnTimeMicroSec) {
log.warn("Runnable {}:{} took too long {} micros to execute.", runnable, runnable.getClass(),
elapsedMicroSec);
log.warn("Runnable {} took too long {} micros to execute.", runnableClass, elapsedMicroSec);
}
}
}
Expand All @@ -216,10 +217,12 @@ public void run() {
protected class TimedCallable<T> implements Callable<T> {
final Callable<T> callable;
final long initNanos;
final Class<?> callableClass;

TimedCallable(Callable<T> callable) {
this.callable = callable;
this.initNanos = MathUtils.nowInNano();
this.callableClass = callable.getClass();
}

@Override
Expand All @@ -232,8 +235,7 @@ public T call() throws Exception {
long elapsedMicroSec = MathUtils.elapsedMicroSec(startNanos);
taskExecutionStats.registerSuccessfulEvent(elapsedMicroSec, TimeUnit.MICROSECONDS);
if (elapsedMicroSec >= warnTimeMicroSec) {
log.warn("Callable {}:{} took too long {} micros to execute.", callable, callable.getClass(),
elapsedMicroSec);
log.warn("Callable {} took too long {} micros to execute.", callableClass, elapsedMicroSec);
}
}
}
Expand Down

0 comments on commit 43b5ccc

Please sign in to comment.