package com.ruoyi.projetctCost.ThreadPool;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/*装机成本计算专用线程池*/
public class InstallationCostSummaryThreadPool {
    private static volatile InstallationCostSummaryThreadPool instance;
    private final ThreadPoolExecutor executor;
    private InstallationCostSummaryThreadPool() {
        // 私有构造方法
        int corePoolSize = 5; // 核心线程池大小
        int maxPoolSize = 10; // 最大线程池大小
        long keepAliveTime = 60L; // 线程空闲时间
        TimeUnit unit = TimeUnit.SECONDS; // 线程空闲时间单位
        BlockingQueue<Runnable> workQueue = new ArrayBlockingQueue<>(50); // 任务队列
        executor = new ThreadPoolExecutor(corePoolSize, maxPoolSize, keepAliveTime, unit, workQueue);
    }
    public static InstallationCostSummaryThreadPool getInstance() {
        if (instance == null) {
            synchronized (InstallationCostSummaryThreadPool.class) {
                if (instance == null) {
                    instance = new InstallationCostSummaryThreadPool();
                }
            }
        }
        return instance;
    }
    public ThreadPoolExecutor getExecutor() {
        return executor;
    }
}
