package com.nokia.alarm.config;

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

@Slf4j
@Configuration

public class SchedulingConfig {

    @Value("${scheduling.scheduler.pool.size:5}")
    private int poolSize;

    @Bean
    public ThreadPoolTaskScheduler taskScheduler() {
        // 使用最常用的ThreadPoolTaskScheduler
        ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
        // 线程数
        taskScheduler.setPoolSize(poolSize);
        taskScheduler.setRemoveOnCancelPolicy(true);
        taskScheduler.setThreadNamePrefix("taskSchedulerThreadPool-");
        log.info("已完成 ThreadPoolTaskScheduler 配置, poolSize = {}", poolSize);
        return taskScheduler;
    }

    

}
