From 8e56a519c00f77da3053738946dedbb7801a9139 Mon Sep 17 00:00:00 2001
From: Robert Scott <code@humanleg.org.uk>
Date: Sat, 12 May 2018 11:23:23 +0100
Subject: [PATCH v2 24/28] ProgressMonitorExecutor: log exceptions raised by
runnables
---
.../progress/swing/ProgressMonitorExecutor.java | 23 ++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/src/org/openstreetmap/josm/gui/progress/swing/ProgressMonitorExecutor.java b/src/org/openstreetmap/josm/gui/progress/swing/ProgressMonitorExecutor.java
index 2a7f7de56..d046344f6 100644
a
|
b
|
|
1 | 1 | // License: GPL. For details, see LICENSE file. |
2 | 2 | package org.openstreetmap.josm.gui.progress.swing; |
3 | 3 | |
| 4 | import java.util.concurrent.CancellationException; |
| 5 | import java.util.concurrent.ExecutionException; |
| 6 | import java.util.concurrent.Future; |
4 | 7 | import java.util.concurrent.LinkedBlockingQueue; |
5 | 8 | import java.util.concurrent.ThreadPoolExecutor; |
6 | 9 | import java.util.concurrent.TimeUnit; |
7 | 10 | |
| 11 | import org.openstreetmap.josm.tools.Logging; |
8 | 12 | import org.openstreetmap.josm.tools.Utils; |
9 | 13 | |
10 | 14 | /** |
… |
… |
public class ProgressMonitorExecutor extends ThreadPoolExecutor {
|
36 | 40 | super.execute(command); |
37 | 41 | } |
38 | 42 | |
| 43 | @Override |
| 44 | public void afterExecute(final Runnable r, Throwable t) { |
| 45 | // largely as proposed by JDK8 docs |
| 46 | super.afterExecute(r, t); |
| 47 | if (t == null && r instanceof Future<?>) { |
| 48 | try { |
| 49 | Object result = ((Future<?>) r).get(); |
| 50 | } catch (CancellationException cancellationException) { |
| 51 | t = cancellationException; |
| 52 | } catch (ExecutionException executionException) { |
| 53 | t = executionException.getCause(); |
| 54 | } catch (InterruptedException interruptedException) { |
| 55 | Thread.currentThread().interrupt(); // ignore/reset |
| 56 | } |
| 57 | } |
| 58 | if (t != null) { |
| 59 | Logging.error("Thread {0} raised {1}", Thread.currentThread().getName(), t); |
| 60 | } |
| 61 | } |
39 | 62 | } |