//package com.qmth.themis.business.threadPool;
//
//import com.qmth.themis.business.constant.SystemConstant;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.Primary;
//import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
//
//import javax.annotation.PostConstruct;
//import java.util.Objects;
//import java.util.concurrent.Executor;
//import java.util.concurrent.ThreadPoolExecutor;
//
///**
// * @Description: 线程池应用配置
// * @Param:
// * @return:
// * @Author: wangliang
// * @Date: 2019/3/21
// */
//@Configuration
//public class MyThreadPool extends ThreadPoolTaskExecutor {
//    private final static Logger log = LoggerFactory.getLogger(MyThreadPool.class);
//    private MyThreadPool threadPoolTaskExecutor = null;
//    static final int cpuNum = Runtime.getRuntime().availableProcessors();
//
//    /**
//     * 线程池
//     *
//     * @return
//     */
//    @Bean
//    @Primary
//    public Executor taskThreadPool() {
//        if (Objects.isNull(threadPoolTaskExecutor)) {
//            log.info("cpuNum:{}", cpuNum);
//            threadPoolTaskExecutor = new MyThreadPool();
//            threadPoolTaskExecutor.setCorePoolSize(cpuNum);//核心线程数
//            threadPoolTaskExecutor.setMaxPoolSize(cpuNum * 2);//最大线程数
//            threadPoolTaskExecutor.setKeepAliveSeconds(SystemConstant.THREAD_POOL_KEEP_ALIVE_SECONDS);//线程空闲时间
//            threadPoolTaskExecutor.setQueueCapacity(SystemConstant.THREAD_POOL_QUEUE_CAPACITY);//队列容量
//            threadPoolTaskExecutor.setThreadNamePrefix(SystemConstant.THREAD_POOL_NAME);
//            threadPoolTaskExecutor.setAllowCoreThreadTimeOut(true);//设置是否允许核心线程超时。若允许，核心线程超时后，会被销毁。默认为不允许（fasle）
//            threadPoolTaskExecutor.setWaitForTasksToCompleteOnShutdown(true);//设置shutdown时是否等到所有任务完成再真正关闭
//            threadPoolTaskExecutor.setAwaitTerminationSeconds(60);//当setWaitForTasksToCompleteOnShutdown(true)时，setAwaitTerminationSeconds 设置在 shutdown 之后最多等待多长时间后再真正关闭线程池
//            // rejection-policy：当pool已经达到max size的时候，如何处理新任务
//            // CALLER_RUNS：不在新线程中执行任务，而是由调用者所在的线程来执行
//            threadPoolTaskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
//            threadPoolTaskExecutor.initialize();
//        }
//        return threadPoolTaskExecutor;
//    }
//
//    public MyThreadPool getThreadPoolTaskExecutor() {
//        return threadPoolTaskExecutor;
//    }
//}
