package com.kym.admin.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;

/**
 * 调度线程池配置
 * ScheduledExecutorService 暂不支持虚拟线程，所以用 2 线程调度器负责触发，
 * 实际工作在 @Async("AsyncExecutor") 的虚拟线程上执行，不阻塞调度线程。
 *
 * @author skyline
 */
@Configuration
@Slf4j
public class SchedulingConfig {

    @Bean
    public TaskScheduler taskScheduler() {
        log.info("初始化调度线程池（虚拟线程模式）");
        ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
        scheduler.setPoolSize(2);
        scheduler.setThreadGroupName("admin-schedule");
        scheduler.setThreadNamePrefix("sched-");
        scheduler.initialize();
        return scheduler;
    }
}
