1.自定义定时任务线程池
package com.x.devicetcpserver.global.tcp.tcpscheduler;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
@Configuration
@EnableConfigurationProperties(ScheduledProperties.class)
public class TaskSchedulerConfig {
@Bean
public ThreadPoolTaskScheduler taskScheduler() {
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
// 设置线程池大小
scheduler.setPoolSize(Runtime.getRuntime().availableProcessors() * 2 + 1);
// 设置线程名称前缀
scheduler.setThreadNamePrefix("my-task-sc