You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bookkeeper.apache.org by sh...@apache.org on 2024/06/10 23:48:44 UTC
(bookkeeper) 02/02: Fix TimedRunnable log NPE (#4425)
This is an automated email from the ASF dual-hosted git repository.
shoothzj pushed a commit to branch branch-4.17
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git
commit 8331873d38dd8398a9c0cb34ffeb90c9f366c4d3
Author: houxiaoyu <ho...@apache.org>
AuthorDate: Tue Jun 11 07:41:10 2024 +0800
Fix TimedRunnable log NPE (#4425)
---
.../org/apache/bookkeeper/common/util/OrderedExecutor.java | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/bookkeeper-common/src/main/java/org/apache/bookkeeper/common/util/OrderedExecutor.java b/bookkeeper-common/src/main/java/org/apache/bookkeeper/common/util/OrderedExecutor.java
index f856a4ea32..a6f137f4aa 100644
--- a/bookkeeper-common/src/main/java/org/apache/bookkeeper/common/util/OrderedExecutor.java
+++ b/bookkeeper-common/src/main/java/org/apache/bookkeeper/common/util/OrderedExecutor.java
@@ -187,10 +187,12 @@ public class OrderedExecutor implements ExecutorService {
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
@@ -203,8 +205,7 @@ public class OrderedExecutor implements ExecutorService {
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);
}
}
}
@@ -216,10 +217,12 @@ public class OrderedExecutor implements ExecutorService {
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
@@ -232,8 +235,7 @@ public class OrderedExecutor implements ExecutorService {
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);
}
}
}