Committed by
Thomas Vachuska
[ONOS-3528] Log exception for all threads that use BoundedThreadPool
Change-Id: I9c904c49998a8206ba2b5a084e03e776fa1d8237
Showing
1 changed file
with
24 additions
and
0 deletions
| ... | @@ -16,6 +16,8 @@ | ... | @@ -16,6 +16,8 @@ |
| 16 | package org.onlab.util; | 16 | package org.onlab.util; |
| 17 | 17 | ||
| 18 | import java.util.concurrent.Callable; | 18 | import java.util.concurrent.Callable; |
| 19 | +import java.util.concurrent.CancellationException; | ||
| 20 | +import java.util.concurrent.ExecutionException; | ||
| 19 | import java.util.concurrent.Future; | 21 | import java.util.concurrent.Future; |
| 20 | import java.util.concurrent.LinkedBlockingQueue; | 22 | import java.util.concurrent.LinkedBlockingQueue; |
| 21 | import java.util.concurrent.RejectedExecutionHandler; | 23 | import java.util.concurrent.RejectedExecutionHandler; |
| ... | @@ -111,6 +113,28 @@ public final class BoundedThreadPool extends ThreadPoolExecutor { | ... | @@ -111,6 +113,28 @@ public final class BoundedThreadPool extends ThreadPoolExecutor { |
| 111 | updateLoad(); | 113 | updateLoad(); |
| 112 | } | 114 | } |
| 113 | 115 | ||
| 116 | + @Override | ||
| 117 | + protected void afterExecute(Runnable r, Throwable t) { | ||
| 118 | + super.afterExecute(r, t); | ||
| 119 | + if (t == null && r instanceof Future<?>) { | ||
| 120 | + try { | ||
| 121 | + Future<?> future = (Future<?>) r; | ||
| 122 | + if (future.isDone()) { | ||
| 123 | + future.get(); | ||
| 124 | + } | ||
| 125 | + } catch (CancellationException ce) { | ||
| 126 | + t = ce; | ||
| 127 | + } catch (ExecutionException ee) { | ||
| 128 | + t = ee.getCause(); | ||
| 129 | + } catch (InterruptedException ie) { | ||
| 130 | + Thread.currentThread().interrupt(); | ||
| 131 | + } | ||
| 132 | + } | ||
| 133 | + if (t != null) { | ||
| 134 | + log.error("Uncaught exception on " + r.getClass().getSimpleName(), t); | ||
| 135 | + } | ||
| 136 | + } | ||
| 137 | + | ||
| 114 | // TODO schedule this with a fixed delay from a scheduled executor | 138 | // TODO schedule this with a fixed delay from a scheduled executor |
| 115 | private final AtomicLong lastPrinted = new AtomicLong(0L); | 139 | private final AtomicLong lastPrinted = new AtomicLong(0L); |
| 116 | 140 | ... | ... |
-
Please register or login to post a comment