package com.yingpai.stock.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.ThreadPoolExecutor;

@Configuration
public class StockThreadPoolConfig {
    /**
     * 股票行情获取专用线程池
     * 核心线程数：5（控制并发，避免被API限流）
     * 最大线程数：10
     * 队列容量：100
     */
    @Bean("stockQuoteExecutor")
    public ThreadPoolTaskExecutor stockQuoteExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(5);
        executor.setMaxPoolSize(10);
        executor.setQueueCapacity(100);
        executor.setKeepAliveSeconds(60);
        executor.setThreadNamePrefix("stock-quote-");
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
        executor.initialize();
        return executor;
    }
}
