From 7953211fc5bbc0054064913db89116f76f47e0b1 Mon Sep 17 00:00:00 2001 From: RuoYi Date: Fri, 15 Mar 2019 18:19:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8D=95=E8=8E=B7=E7=BA=BF=E7=A8=8B=E6=B1=A0?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E4=BB=BB=E5=8A=A1=E6=8A=9B=E5=87=BA=E7=9A=84?= =?UTF-8?q?=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/thread/ThreadPoolConfig.java | 52 +++++++++++++------ 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/config/thread/ThreadPoolConfig.java b/ruoyi-common/src/main/java/com/ruoyi/common/config/thread/ThreadPoolConfig.java index e1292d2e..6638b6b4 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/config/thread/ThreadPoolConfig.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/config/thread/ThreadPoolConfig.java @@ -55,25 +55,45 @@ public class ThreadPoolConfig protected ScheduledExecutorService scheduledExecutorService() { return new ScheduledThreadPoolExecutor(corePoolSize, - new BasicThreadFactory.Builder().namingPattern("schedule-pool-%d").daemon(true).build()) { + new BasicThreadFactory.Builder().namingPattern("schedule-pool-%d").daemon(true).build()) + { @Override - protected void afterExecute(Runnable r, Throwable t) { + protected void afterExecute(Runnable r, Throwable t) + { super.afterExecute(r, t); - if (t == null && r instanceof Future) { - try { - Object result = ((Future) r).get(); - } catch (CancellationException ce) { - t = ce; - } catch (ExecutionException ee) { - t = ee.getCause(); - } catch (InterruptedException ie) { - Thread.currentThread().interrupt(); // ignore/reset - } - } - if(t != null) { - log.error(t.getMessage()); - } + printException(r, t); } }; } + + private static void printException(Runnable r, Throwable t) + { + if (t == null && r instanceof Future) + { + try + { + Future future = (Future) r; + if (future.isDone()) + { + future.get(); + } + } + catch (CancellationException ce) + { + t = ce; + } + catch (ExecutionException ee) + { + t = ee.getCause(); + } + catch (InterruptedException ie) + { + Thread.currentThread().interrupt(); + } + } + if (t != null) + { + log.error(t.getMessage(), t); + } + } }