From aad585bdff0da11c62f9611c13b933248ef1fa3e Mon Sep 17 00:00:00 2001 From: geekymv Date: Wed, 13 Mar 2019 22:14:03 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=B0=E5=BD=95=E5=BC=82=E5=B8=B8=E6=97=A5?= =?UTF-8?q?=E5=BF=97(=E9=BB=98=E8=AE=A4=E6=83=85=E5=86=B5=E4=B8=8B?= =?UTF-8?q?=EF=BC=8C=E7=BA=BF=E7=A8=8B=E6=B1=A0=E4=BC=9A=E6=8D=95=E8=8E=B7?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E6=8A=9B=E5=87=BA=E7=9A=84=E6=89=80=E6=9C=89?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=EF=BC=8C=E4=BD=86=E6=98=AF=E4=B8=8D=E5=81=9A?= =?UTF-8?q?=E4=BB=BB=E4=BD=95=E5=A4=84=E7=90=86)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/thread/ThreadPoolConfig.java | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) 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 1fa05d3e..e1292d2e 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 @@ -1,9 +1,14 @@ package com.ruoyi.common.config.thread; +import java.util.concurrent.CancellationException; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor; import org.apache.commons.lang3.concurrent.BasicThreadFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; @@ -16,6 +21,8 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; @Configuration public class ThreadPoolConfig { + private static final Logger log = LoggerFactory.getLogger(ThreadPoolConfig.class); + // 核心线程池大小 private int corePoolSize = 50; @@ -48,6 +55,25 @@ 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) { + 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()); + } + } + }; } }