public class ThreadPoolUtils extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static int |
THREAD_PRIORITY_HIGH
高任务优先级,默认10
|
static int |
THREAD_PRIORITY_LOW
低任务优先级,默认-10
|
static int |
THREAD_PRIORITY_NORMAL
普通任务优先级,默认0
|
| 构造器和说明 |
|---|
ThreadPoolUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static BlockingQueue<Runnable> |
buildQueue(int size)
构建队列
|
static BlockingQueue<Runnable> |
buildQueue(int size,
boolean isPriority)
构建队列
|
static ThreadPoolExecutor |
newCachedThreadPool(int corePoolSize,
int maximumPoolSize)
缓冲线程池(1分钟无调用销毁),无队列
|
static ThreadPoolExecutor |
newCachedThreadPool(int corePoolSize,
int maximumPoolSize,
BlockingQueue<Runnable> queue)
缓冲线程池(1分钟无调用销毁),自定义队列
|
static ThreadPoolExecutor |
newCachedThreadPool(int corePoolSize,
int maximumPoolSize,
BlockingQueue<Runnable> queue,
ThreadFactory threadFactory)
缓冲线程池(1分钟无调用销毁),自定义队列和线程池工厂
|
static ThreadPoolExecutor |
newCachedThreadPool(int corePoolSize,
int maximumPoolSize,
BlockingQueue<Runnable> queue,
ThreadFactory threadFactory,
RejectedExecutionHandler handler)
缓冲线程池(1分钟无调用销毁),自定义队列、线程池工厂和拒绝策略
|
static ThreadPoolExecutor |
newCachedThreadPool(int corePoolSize,
int maximumPoolSize,
int keepAliveTime,
BlockingQueue<Runnable> queue,
ThreadFactory threadFactory,
RejectedExecutionHandler handler)
缓冲线程池(1分钟无调用销毁),自定义队列、线程池工厂和拒绝策略
|
static ThreadPoolExecutor |
newFixedThreadPool(int corePoolSize)
固定大小线程池,无队列
|
static ThreadPoolExecutor |
newFixedThreadPool(int corePoolSize,
BlockingQueue<Runnable> queue)
固定大小线程池,自定义队列
|
static ThreadPoolExecutor |
newFixedThreadPool(int corePoolSize,
BlockingQueue<Runnable> queue,
ThreadFactory threadFactory)
固定大小线程池,自定义队列和线程池工厂
|
static ThreadPoolExecutor |
newFixedThreadPool(int corePoolSize,
BlockingQueue<Runnable> queue,
ThreadFactory threadFactory,
RejectedExecutionHandler handler)
固定大小线程池,自定义队列、线程池工厂和拒绝策略
|
public static int THREAD_PRIORITY_NORMAL
public static int THREAD_PRIORITY_HIGH
public static int THREAD_PRIORITY_LOW
public static ThreadPoolExecutor newFixedThreadPool(int corePoolSize)
corePoolSize - 初始化线程池public static ThreadPoolExecutor newFixedThreadPool(int corePoolSize, BlockingQueue<Runnable> queue)
corePoolSize - 初始化线程池queue - 线程池队列public static ThreadPoolExecutor newFixedThreadPool(int corePoolSize, BlockingQueue<Runnable> queue, ThreadFactory threadFactory)
corePoolSize - 初始化线程池queue - 线程池队列threadFactory - 线程池工厂public static ThreadPoolExecutor newFixedThreadPool(int corePoolSize, BlockingQueue<Runnable> queue, ThreadFactory threadFactory, RejectedExecutionHandler handler)
corePoolSize - 初始化线程池queue - 线程池队列threadFactory - 线程池工厂handler - 拒绝策略public static ThreadPoolExecutor newCachedThreadPool(int corePoolSize, int maximumPoolSize)
corePoolSize - 初始化线程池maximumPoolSize - 最大线程池public static ThreadPoolExecutor newCachedThreadPool(int corePoolSize, int maximumPoolSize, BlockingQueue<Runnable> queue)
corePoolSize - 初始化线程池maximumPoolSize - 最大线程池queue - 线程池队列public static ThreadPoolExecutor newCachedThreadPool(int corePoolSize, int maximumPoolSize, BlockingQueue<Runnable> queue, ThreadFactory threadFactory)
corePoolSize - 初始化线程池maximumPoolSize - 最大线程池queue - 线程池队列threadFactory - 线程池工厂public static ThreadPoolExecutor newCachedThreadPool(int corePoolSize, int maximumPoolSize, BlockingQueue<Runnable> queue, ThreadFactory threadFactory, RejectedExecutionHandler handler)
corePoolSize - 初始化线程池maximumPoolSize - 最大线程池queue - 线程池队列threadFactory - 线程池工厂handler - 拒绝策略public static ThreadPoolExecutor newCachedThreadPool(int corePoolSize, int maximumPoolSize, int keepAliveTime, BlockingQueue<Runnable> queue, ThreadFactory threadFactory, RejectedExecutionHandler handler)
corePoolSize - 初始化线程池maximumPoolSize - 最大线程池keepAliveTime - 回收时间queue - 线程池队列threadFactory - 线程池工厂handler - 拒绝策略public static BlockingQueue<Runnable> buildQueue(int size)
size - 队列大小public static BlockingQueue<Runnable> buildQueue(int size, boolean isPriority)
size - 队列大小isPriority - 是否优先级队列Copyright © 2008–2018 The Ant Financial. All rights reserved.