线程池及调用

package com.neusoft.mid.cpap.flowresult.check;

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

public final class ThreadPool {

    private ThreadPool() {
    }

    private static ThreadPool instance = new ThreadPool();

    public static ThreadPool getInstance() {
        return instance;
    }

    private static final int QUEUE_SIZE = 10000;

    private static final int MIN_SIZE = 10;

    private static final int MAX_SIZE = 20;

    private static final int KEEP_LIVE_TIME = 5;

    @SuppressWarnings({ "rawtypes", "unchecked" })
    private ThreadPoolExecutor threadPool = new ThreadPoolExecutor(MIN_SIZE, MAX_SIZE,
            KEEP_LIVE_TIME,

            TimeUnit.SECONDS, new ArrayBlockingQueue(QUEUE_SIZE), new RejectedExecutionHandler() {

                public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {

                    System.out.println("threadPool queue is full.");

                }

            });

    public ThreadPoolExecutor getThreadPool() {
        return threadPool;
    }

}

H2 调用

ThreadPool.getInstance().getThreadPool().execute(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            //业务代码
                            //flowManageTabService.monitorFlow(monitor);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                });



你可能感兴趣的:(线程池及调用)