| New file | 
|  |  |  | 
|---|
|  |  |  | package com.dy.common.threadPool; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public class TreadPoolFactory { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private static ThreadPool.Pool pool_short ;//短工作任务线程池,线程工作用时较短 | 
|---|
|  |  |  | private static ThreadPool.Pool pool_long ;//长工作任务线程池,线程工作用时较长 | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public final static Integer[] pool_short_state(){ | 
|---|
|  |  |  | Integer shortCurThread = 0 ;//短线程池当前线程数 | 
|---|
|  |  |  | Integer shortMaxThread = 0 ;//短线程池最大线程数 | 
|---|
|  |  |  | Integer shortMinThread = 0 ;//短线程池最小线程数 | 
|---|
|  |  |  | shortCurThread = pool_short.size() ; | 
|---|
|  |  |  | shortMaxThread = pool_short.maxThread() ; | 
|---|
|  |  |  | shortMinThread = pool_short.minThread() ; | 
|---|
|  |  |  | return new Integer[]{shortCurThread, shortMaxThread, shortMinThread} ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public final static Integer[] pool_long_state(){ | 
|---|
|  |  |  | Integer longCurThread = 0 ;//短线程池当前线程数 | 
|---|
|  |  |  | Integer longMaxThread = 0 ;//短线程池最大线程数 | 
|---|
|  |  |  | Integer longMinThread = 0 ;//短线程池最小线程数 | 
|---|
|  |  |  | longCurThread = pool_long.size() ; | 
|---|
|  |  |  | longMaxThread = pool_long.maxThread() ; | 
|---|
|  |  |  | longMinThread = pool_long.minThread() ; | 
|---|
|  |  |  | return new Integer[]{longCurThread, longMaxThread, longMinThread} ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 初始化线程池 | 
|---|
|  |  |  | * @param poolName 线程池和线程名称 | 
|---|
|  |  |  | * @param maxNum 线程池最大线程数 ,若为-1,不受限制 | 
|---|
|  |  |  | * @param minNum 线程池最小线程数,或初始线程数 | 
|---|
|  |  |  | * @param freeTimeout 空闲线程超时时长(秒) | 
|---|
|  |  |  | * @param busyTimeout 忙碌线程超时时长(秒),若为-1,不受限制 | 
|---|
|  |  |  | * @return 线程池实例 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public final static void initThreadPoolShort(String poolName, | 
|---|
|  |  |  | int maxNum, | 
|---|
|  |  |  | int minNum, | 
|---|
|  |  |  | long freeTimeout, | 
|---|
|  |  |  | long busyTimeout) throws Exception { | 
|---|
|  |  |  | if(pool_short!= null){ | 
|---|
|  |  |  | throw new Exception("线程池不能重复初始化!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(pool_short == null){ | 
|---|
|  |  |  | pool_short = new ThreadPoolImp().new MyThreadPool(poolName, maxNum, minNum, freeTimeout, busyTimeout); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 初始化线程池 | 
|---|
|  |  |  | * @param poolName 线程池和线程名称 | 
|---|
|  |  |  | * @param maxNum 线程池最大线程数,若为-1,不受限制 | 
|---|
|  |  |  | * @param minNum 线程池最小线程数,或初始线程数 | 
|---|
|  |  |  | * @param freeTimeout 空闲线程超时时长(秒) | 
|---|
|  |  |  | * @param busyTimeout 忙碌线程超时时长(秒),若为-1,不受限制 | 
|---|
|  |  |  | * @return 线程池实例 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public final static void initThreadPoolLong(String poolName, | 
|---|
|  |  |  | int maxNum, | 
|---|
|  |  |  | int minNum, | 
|---|
|  |  |  | long freeTimeout, | 
|---|
|  |  |  | long busyTimeout) throws Exception { | 
|---|
|  |  |  | if(pool_long!= null){ | 
|---|
|  |  |  | throw new Exception("线程池不能重复初始化!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(pool_long == null){ | 
|---|
|  |  |  | pool_long =  new ThreadPoolImp().new MyThreadPool(poolName, maxNum, minNum, freeTimeout, busyTimeout); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 得到唯一线程池实例 | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | * @throws Exception | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public final static ThreadPool.Pool getThreadPoolShort() | 
|---|
|  |  |  | throws Exception { | 
|---|
|  |  |  | if (pool_short == null) { | 
|---|
|  |  |  | throw new Exception("得到线程池前首先必须初始化!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return pool_short ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 得到唯一线程池实例 | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | * @throws Exception | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public final static ThreadPool.Pool getThreadPoolLong() | 
|---|
|  |  |  | throws Exception { | 
|---|
|  |  |  | if (pool_long == null) { | 
|---|
|  |  |  | throw new Exception("得到线程池前首先必须初始化!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return pool_long ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|