package com.ycwl.basic.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;

@Configuration
@EnableScheduling
public class SchedulerConfig {

    @Bean
    public ThreadPoolTaskScheduler taskScheduler() {
        ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
        scheduler.setPoolSize(32);                // 核心/最大线程数
        scheduler.setAwaitTerminationSeconds(0);  // 空闲线程存活时间（秒）
        scheduler.setThreadNamePrefix("Scheduler-");
        scheduler.setAwaitTerminationSeconds(60); // 等待任务终止的时间
        scheduler.setRemoveOnCancelPolicy(true);  // 取消任务后移除线程
        return scheduler;
    }
}