package com.ruoyi.ccdi.project.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 BankTagThreadPoolConfig {

    /**
     * 项目级重打标异步调度线程池
     *
     * @return 线程池执行器
     */
    @Bean("tagRebuildExecutor")
    public Executor tagRebuildExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(2);
        executor.setMaxPoolSize(4);
        executor.setQueueCapacity(100);
        executor.setThreadNamePrefix("bank-tag-rebuild-");
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());
        executor.initialize();
        return executor;
    }

    /**
     * 规则级并行执行线程池
     *
     * @return 线程池执行器
     */
    @Bean("tagRuleExecutor")
    public Executor tagRuleExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(4);
        executor.setMaxPoolSize(8);
        executor.setQueueCapacity(100);
        executor.setThreadNamePrefix("bank-tag-rule-");
        executor.initialize();
        return executor;
    }
}
