标签:adt alt 不同的 val efault img 运行 hashset exce
public static ExecutorService newFixedThreadPool(int nThreads) {
return new ThreadPoolExecutor(nThreads, nThreads, 0L, TimeUnit.MILLISECONDS,new LinkedBlockingQueue<Runnable>());
}
public static ExecutorService newCachedThreadPool() {
return new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>());
}
public static ExecutorService newSingleThreadExecutor() {
return new FinalizableDelegatedExecutorService
(new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>()));
}
private static final RejectedExecutionHandler defaultHandler = new AbortPolicy();
public ThreadPoolExecutor(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit,
BlockingQueue<Runnable> workQueue) {
this(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue,
Executors.defaultThreadFactory(), defaultHandler);
}
public interface ExecutorService extends Executor {
void shutdown();
List<Runnable> shutdownNow();
boolean isShutdown();
boolean isTerminated();
boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException;
// 省略部分方法
}
1. private final BlockingQueue<Runnable> workQueue; // 阻塞队列
2. private final ReentrantLock mainLock = new ReentrantLock(); // 互斥锁
3. private final HashSet<Worker> workers = new HashSet<Worker>();// 线程集合.一个Worker对应一个线程
4. private final Condition termination = mainLock.newCondition();// 终止条件
5. private int largestPoolSize; // 线程池中线程数量曾经达到过的最大值。
6. private long completedTaskCount; // 已完成任务数量
7. private volatile ThreadFactory threadFactory; // ThreadFactory对象,用于创建线程。
8. private volatile RejectedExecutionHandler handler;// 拒绝策略的处理句柄
9. private volatile long keepAliveTime; // 线程池维护线程所允许的空闲时间
10. private volatile boolean allowCoreThreadTimeOut;
11. private volatile int corePoolSize; // 线程池维护线程的最小数量,哪怕是空闲的
12. private volatile int maximumPoolSize; // 线程池维护的最大线程数量
标签:adt alt 不同的 val efault img 运行 hashset exce
原文地址:http://www.cnblogs.com/ITtangtang/p/7608801.html