From 531a7255925c29d4903e01131238b20f89fbf282 Mon Sep 17 00:00:00 2001 From: Luoye_W Date: Wed, 28 Jul 2021 15:54:03 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4webflux=E4=BE=9D=E8=B5=96=20?= =?UTF-8?q?=E6=9B=B4=E6=94=B9=E8=B0=83=E7=94=A8=E6=A8=A1=E5=BC=8F=E4=B8=BA?= =?UTF-8?q?=E7=BA=BF=E7=A8=8B=E6=B1=A0=EF=BC=8C=E5=8F=96=E6=B6=88rabbitMQ?= =?UTF-8?q?=E9=98=9F=E5=88=97=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/io/qyi/e5/config/Start.java | 41 +++++++++++------------ 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/src/main/java/io/qyi/e5/config/Start.java b/src/main/java/io/qyi/e5/config/Start.java index 8950299..44e9472 100644 --- a/src/main/java/io/qyi/e5/config/Start.java +++ b/src/main/java/io/qyi/e5/config/Start.java @@ -14,7 +14,6 @@ import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; -import java.time.LocalDateTime; import java.util.List; import java.util.concurrent.*; @@ -37,35 +36,35 @@ public class Start { IOutlookService outlookService; @Value("${e5.system.threadPool}") - private int poolSize = 10; + Integer poolSize; + + private ExecutorService threadPool; - private ExecutorService threadPool = new ThreadPoolExecutor( - //指定了线程池中的线程数量,它的数量决定了添加的任务是开辟新的线程去执行,还是放到workQueue任务队列中去; - poolSize, - //指定了线程池中的最大线程数量,这个参数会根据你使用的workQueue任务队列的类型,决定线程池会开辟的最大线程数量; - poolSize, - //当线程池中空闲线程数量超过corePoolSize时,多余的线程会在多长时间内被销毁; - 0, - //unit:keepAliveTime的单位 - TimeUnit.MILLISECONDS, - //任务队列,被添加到线程池中,但尚未被执行的任务;它一般分为直接提交队列、有界任务队列、无界任务队列、优先任务队列几种; - new LinkedBlockingQueue<>(poolSize), // 有界队列 - //线程工厂,用于创建线程,一般用默认即可; new CustThreadFactory(), - Executors.defaultThreadFactory(), - //拒绝策略;当任务太多来不及处理时,如何拒绝任务; - new CustRejectedExecutionHandler() - ); @PostConstruct public void init() { log.info("清空redis...... "); redisUtil.delAll(); - /* log.info("重新添加队列...... "); - Task.sendTaskOutlookMQALL();*/ + threadPool = new ThreadPoolExecutor( + //指定了线程池中的线程数量,它的数量决定了添加的任务是开辟新的线程去执行,还是放到workQueue任务队列中去; + poolSize, + //指定了线程池中的最大线程数量,这个参数会根据你使用的workQueue任务队列的类型,决定线程池会开辟的最大线程数量; + poolSize, + //当线程池中空闲线程数量超过corePoolSize时,多余的线程会在多长时间内被销毁; + 0, + //unit:keepAliveTime的单位 + TimeUnit.MILLISECONDS, + //任务队列,被添加到线程池中,但尚未被执行的任务;它一般分为直接提交队列、有界任务队列、无界任务队列、优先任务队列几种; + new LinkedBlockingQueue<>(poolSize), // 有界队列 + //线程工厂,用于创建线程,一般用默认即可; new CustThreadFactory(), + Executors.defaultThreadFactory(), + //拒绝策略;当任务太多来不及处理时,如何拒绝任务; + new CustRejectedExecutionHandler() + ); } - @Scheduled(cron = "0/10 * * * * ?") + @Scheduled(cron = "0 0/1 * * * ? ") private void distributeTask() { List runOutlookList = outlookService.findRunOutlookList(); CountDownLatch cdl = new CountDownLatch(runOutlookList.size());