一个简单的线程池工具类

JASONOSC 发布于 2014/11/14 15:30
阅读 305
收藏 5
    private static ReptileTaskPool instance = new ReptileTaskPool();

	private static final int corePoolSize = 20;
	private static final int maximumPoolSize = 100;
	private static BlockingQueue<Runnable> workQueue = new ArrayBlockingQueue<Runnable>(maximumPoolSize);

        private static ThreadFactory factory = new ThreadFactory() {
		public Thread newThread(Runnable r) {
			Thread t = new Thread(r);
			return t;
		}
	};

	private static ThreadPoolExecutor executor = new ThreadPoolExecutor(
			corePoolSize, maximumPoolSize, 24, TimeUnit.HOURS, workQueue,
			factory);

	public static synchronized ReptileTaskPool sharedInstance() {
		synchronized (ReptileTaskPool.class) {
			if (instance == null) {
				instance = new ReptileTaskPool();
			}
			return instance;
		}
	}

	public void doTask(IReptileTask task) {
		executor.execute(task);
	}

	public void doRun(Runnable task) {
		executor.execute(task);
	}

	public ThreadPoolExecutor getExecutor() {
		return executor;
	}



加载中
0
刘春辉
刘春辉
没有介绍,没有注释.
返回顶部
顶部