package com.uas.platform.b2b.core.util;

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

/**
 * Created by wangmh on 2017/7/19.
 */
public class ThreadTask {

    private static ThreadTask threadTask = new ThreadTask();

    /**
     * 线程池
     */
    private ThreadPoolExecutor executor;

    /**
     * 核心线程池大小
     */
    private static final int corePoolSize = 5;

    /**
     * 最大线程池大小
     */
    private static final int maximumPoolSize = 10;

    /**
     * 阻塞任务队列
     */
    private BlockingQueue<Runnable> workQueue;

    private ThreadTask() {
        workQueue = new ArrayBlockingQueue<Runnable>(maximumPoolSize);
        this.executor = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, 0L, TimeUnit.MILLISECONDS, workQueue);
    }

    public static ThreadTask getInstance(){
        return threadTask;
    }

    public void execute(Runnable r){
        executor.execute(r);
    }
}
