From 512b0cc8f5606f08b93afb154f0cffd92b93cac8 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: 星期五, 12 五月 2023 14:03:41 +0800 Subject: [PATCH] Merge pull request #847 from xu-bin-bin/wvp-28181-2.0 --- src/main/java/com/genersoft/iot/vmp/conf/ScheduleConfig.java | 30 ++++++++++++++++++++++++++++++ 1 files changed, 30 insertions(+), 0 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/conf/ScheduleConfig.java b/src/main/java/com/genersoft/iot/vmp/conf/ScheduleConfig.java new file mode 100644 index 0000000..432fafb --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/conf/ScheduleConfig.java @@ -0,0 +1,30 @@ +package com.genersoft.iot.vmp.conf; + +import org.apache.commons.lang3.concurrent.BasicThreadFactory; +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.annotation.SchedulingConfigurer; +import org.springframework.scheduling.config.ScheduledTaskRegistrar; + +import java.util.concurrent.ScheduledThreadPoolExecutor; +import java.util.concurrent.ThreadPoolExecutor; + +/** + * "@Scheduled"鏄疭pring妗嗘灦鎻愪緵鐨勪竴绉嶅畾鏃朵换鍔℃墽琛屾満鍒讹紝榛樿鎯呭喌涓嬪畠鏄崟绾跨▼鐨勶紝鍦ㄥ悓鏃舵墽琛屽涓畾鏃朵换鍔℃椂鍙兘浼氬嚭鐜伴樆濉炲拰鎬ц兘闂銆� + * 涓轰簡瑙e喅杩欑鍗曠嚎绋嬬摱棰堥棶棰橈紝鍙互灏嗗畾鏃朵换鍔$殑鎵ц鏈哄埗鏀逛负鏀寔澶氱嚎绋� + */ +@Configuration +public class ScheduleConfig implements SchedulingConfigurer { + + public static final int cpuNum = Runtime.getRuntime().availableProcessors(); + + private static final int corePoolSize = cpuNum; + + private static final String threadNamePrefix = "scheduled-task-pool-%d"; + + @Override + public void configureTasks(ScheduledTaskRegistrar taskRegistrar) { + taskRegistrar.setScheduler(new ScheduledThreadPoolExecutor(corePoolSize, + new BasicThreadFactory.Builder().namingPattern(threadNamePrefix).daemon(true).build(), + new ThreadPoolExecutor.CallerRunsPolicy())); + } +} -- Gitblit v1.8.0