Merge remote-tracking branch 'github/dev/数据库统合' into dev/数据库统合2

dev/数据库统合
648540858 2024-12-13 15:07:55 +08:00
commit 59f1ab4e77
3 changed files with 21 additions and 13 deletions

View File

@ -34,6 +34,7 @@ public class DynamicTask {
threadPoolTaskScheduler.setPoolSize(300);
threadPoolTaskScheduler.setWaitForTasksToCompleteOnShutdown(true);
threadPoolTaskScheduler.setAwaitTerminationSeconds(10);
threadPoolTaskScheduler.setThreadNamePrefix("dynamicTask-");
threadPoolTaskScheduler.initialize();
}

View File

@ -1,13 +1,18 @@
package com.genersoft.iot.vmp.conf;
import org.apache.commons.lang3.concurrent.BasicThreadFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadPoolExecutor;
import static com.genersoft.iot.vmp.conf.ThreadPoolTaskConfig.cpuNum;
/**
* "@Scheduled"Spring线
* 线线
@ -15,16 +20,21 @@ import java.util.concurrent.ThreadPoolExecutor;
@Configuration
public class ScheduleConfig implements SchedulingConfigurer {
public static final int cpuNum = Runtime.getRuntime().availableProcessors();
/**
* 线线
*/
private static final int corePoolSize = Math.max(cpuNum, 20);
private static final int corePoolSize = cpuNum;
private static final String threadNamePrefix = "scheduled-task-pool-%d";
/**
* 线
*/
private static final String threadNamePrefix = "schedule";
@Override
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
taskRegistrar.setScheduler(new ScheduledThreadPoolExecutor(corePoolSize,
ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(corePoolSize,
new BasicThreadFactory.Builder().namingPattern(threadNamePrefix).daemon(true).build(),
new ThreadPoolExecutor.CallerRunsPolicy()));
new ThreadPoolExecutor.CallerRunsPolicy());
taskRegistrar.setScheduler(scheduledThreadPoolExecutor);
}
}

View File

@ -28,11 +28,11 @@ public class ThreadPoolTaskConfig {
/**
* 线线
*/
private static final int corePoolSize = cpuNum;
private static final int corePoolSize = Math.max(cpuNum * 2, 16);
/**
* 线
*/
private static final int maxPoolSize = cpuNum*2;
private static final int maxPoolSize = corePoolSize * 10;
/**
* 线
*/
@ -45,12 +45,9 @@ public class ThreadPoolTaskConfig {
/**
* 线
*/
private static final String threadNamePrefix = "wvp-";
private static final String threadNamePrefix = "async-";
/**
*
* @return
*/
@Bean("taskExecutor") // bean的名称默认为首字母小写的方法名
public ThreadPoolTaskExecutor taskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();