This is an automated email from the ASF dual-hosted git repository.

sijie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git


The following commit(s) were added to refs/heads/master by this push:
     new d8e0a9a  Issue #1700: fixed: TimedRunnable does not anticipate 
exception from wrapped runnable
d8e0a9a is described below

commit d8e0a9aa6097eacd13afc2898f89627a15e59e02
Author: Andrey Yegorov <[email protected]>
AuthorDate: Wed Sep 26 02:41:42 2018 -0700

    Issue #1700: fixed: TimedRunnable does not anticipate exception from 
wrapped runnable
    
    Descriptions of the changes in this PR:
    
    added try/finally around runnable.run()
    
    ### Motivation
    
    To correctly track (metrics/log) runnable that throw unexpected exception.
    
    ### Changes
    
    added try/finally around runnable.run()
    
    Master Issue: #1700
    
    
    
    
    Author: Qi Wang <[email protected]>
    Author: Charan Reddy Guttapalem <[email protected]>
    Author: Sijie Guo <[email protected]>
    Author: Andrey Yegorov <[email protected]>
    
    Reviewers: Sijie Guo <[email protected]>, Enrico Olivelli 
<[email protected]>
    
    This closes #1702 from dlg99/fix/issue_1700_timedrunnable, closes #1700
---
 .../apache/bookkeeper/common/util/OrderedExecutor.java    | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 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 520787b..ab62a68 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,12 +187,15 @@ public class OrderedExecutor implements ExecutorService {
         public void run() {
             
taskPendingStats.registerSuccessfulEvent(MathUtils.elapsedNanos(initNanos), 
TimeUnit.NANOSECONDS);
             long startNanos = MathUtils.nowInNano();
-            this.runnable.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);
+            try {
+                this.runnable.run();
+            } finally {
+                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);
+                }
             }
         }
     }

Reply via email to