package com.sz.admin.monitor.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;

@Configuration
public class CameraThreadPoolConfig {

    @Bean("cameraInspectionExecutor")
    public Executor cameraInspectionExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        // 核心线程数：
        executor.setCorePoolSize(10);
        // 最大线程数：并发峰值
        executor.setMaxPoolSize(50);
        // 队列容量：如果超过核心线程数的任务，先放进队列排队
        executor.setQueueCapacity(200);
        // 线程前缀名，方便以后看日志排查问题
        executor.setThreadNamePrefix("Camera-Inspect-");
        // 拒绝策略：如果队列满了，由调用者所在线程（即定时任务主线程）自己去执行
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
        executor.initialize();
        return executor;
    }
}