package com.ruoyi.common.config;

import org.apache.commons.lang3.concurrent.BasicThreadFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.*;

@Configuration
public class AsyncThreadPoolConfig {

    @Bean("excelImportExecutor")
    public ExecutorService excelImportExecutor() {
        return new ThreadPoolExecutor(
                4, 8,
                60, TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(100),
                new BasicThreadFactory.Builder().namingPattern("excel-import-%d").daemon(true).build(),
                new ThreadPoolExecutor.AbortPolicy()
        );
    }

    @Bean("excelExportExecutor")
    public ExecutorService excelExportExecutor() {
        return new ThreadPoolExecutor(
                4, 8,
                60, TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(100),
                new BasicThreadFactory.Builder().namingPattern("excel-export-%d").daemon(true).build(),
                new ThreadPoolExecutor.AbortPolicy()
        );
    }

}