package com.hzs.common.core.utils;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.concurrent.*;

/**
 * 线程工具类
 */
@Slf4j
@Component
public class ThreadUtils {

    /**
     * 创建线程池
     */
    public static ThreadPoolExecutor threadPoolExecutor;

    static {
        // 核心线程数
        int corePoolSize = 4;
        // 最大线程数
        int maxPoolSize = 8;
        // 非核心线程的空闲时间
        long keepAliveTime = 60;
        // 队列容量
        int queueCapacity = 10;

        log.info("==========初始化线程池==========");
        // 创建线程池
        threadPoolExecutor = new ThreadPoolExecutor(
                corePoolSize,
                maxPoolSize,
                keepAliveTime,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(queueCapacity)
        );
    }

}
