package com.kcim.common.util;


import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.*;

/**
 * 线程池通用
 */
@Slf4j
public class ThreadUtil {

    private static ExecutorService executorService;
    public static final int CPU_NUM = Runtime.getRuntime().availableProcessors();

    public static synchronized ExecutorService getInstance() {
        if (executorService == null) {
            executorService = new ThreadPoolExecutor(
                    CPU_NUM + 1,
                    CPU_NUM * 2,
                    10000,
                    TimeUnit.MILLISECONDS,
                    new LinkedBlockingQueue<Runnable>(),
                    Executors.defaultThreadFactory()
            );
        }
        return executorService;
    }
}
