package com.trs.digital.module.manager.controller.admin.digsearch.hybase.config;

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

import java.util.concurrent.ThreadPoolExecutor;

@Configuration
@EnableAsync
public class AsyncData {

    @Bean(name = "asyncHyBaseTableList")
    public ThreadPoolTaskExecutor taskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        //线程池大小
        executor.setCorePoolSize(3);
        //最大线程池大小
        executor.setMaxPoolSize(3);
        //任务队列容量
        executor.setQueueCapacity(6);
        //线程前缀名
        executor.setThreadNamePrefix("asyncHyBaseTableList-");
        // 任务拒绝策略
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
        executor.setWaitForTasksToCompleteOnShutdown(true);
        executor.setAwaitTerminationSeconds(60);
        executor.initialize();
        return executor;
    }
}
