public final class ThreadPoolExecutors extends Object
Thread pool executor utility 1)maximumPoolSize + CALLER_RUNS:线程池中的线程执行完后,需要等待当前线程执行完后再提交任务 2)keepAliveTimeSeconds:为0则表示线程立即终止 3)allowCoreThreadTimeOut:设置为true时,keepAliveTimeSeconds必须大于0
| 限定符和类型 | 类和说明 |
|---|---|
static class |
ThreadPoolExecutors.Builder |
static class |
ThreadPoolExecutors.PrestartCoreThreadType |
| 限定符和类型 | 字段和说明 |
|---|---|
static RejectedExecutionHandler |
ABORT
Throw RejectedExecutionException
|
static RejectedExecutionHandler |
CALLER_BLOCKS
Synchronized put the current task to queue
|
static RejectedExecutionHandler |
CALLER_RUNS
Caller thread run the current task
|
static RejectedExecutionHandler |
CALLER_RUNS_ANYWAY
Anyway always run, ignore the thread pool is whether shutdown
|
static RejectedExecutionHandler |
CALLER_RUNS_OLDEST
Caller thread run the oldest task
|
static RejectedExecutionHandler |
DISCARD
Discard the current task
|
static RejectedExecutionHandler |
DISCARD_OLDEST
Discard oldest and execute the new
|
static String |
DISJOB_COMMON_SCHEDULED_POOL_SIZE |
static String |
DISJOB_COMMON_THREAD_POOL_SIZE |
static int |
MAX_CAP
max #workers - 1
|
| 构造器和说明 |
|---|
ThreadPoolExecutors() |
| 限定符和类型 | 方法和说明 |
|---|---|
static ThreadPoolExecutors.Builder |
builder() |
static ScheduledThreadPoolExecutor |
commonScheduledPool()
Common ScheduledThreadPoolExecutor
|
static ThreadPoolExecutor |
commonThreadPool()
Common ThreadPoolExecutor, IO bound / IO intensive
|
static boolean |
shutdown(ExecutorService executorService)
Shutdown the ExecutorService safe
|
static boolean |
shutdown(ExecutorService executorService,
int awaitSeconds)
Shutdown the executorService max wait time
|
public static final String DISJOB_COMMON_THREAD_POOL_SIZE
public static final String DISJOB_COMMON_SCHEDULED_POOL_SIZE
public static final int MAX_CAP
public static final RejectedExecutionHandler ABORT
public static final RejectedExecutionHandler DISCARD
public static final RejectedExecutionHandler CALLER_RUNS
public static final RejectedExecutionHandler DISCARD_OLDEST
public static final RejectedExecutionHandler CALLER_RUNS_OLDEST
public static final RejectedExecutionHandler CALLER_BLOCKS
public static final RejectedExecutionHandler CALLER_RUNS_ANYWAY
public static ThreadPoolExecutor commonThreadPool()
public static ScheduledThreadPoolExecutor commonScheduledPool()
public static ThreadPoolExecutors.Builder builder()
public static boolean shutdown(ExecutorService executorService)
executorService - the executorServicepublic static boolean shutdown(ExecutorService executorService, int awaitSeconds)
executorService - the executorServiceawaitSeconds - await time secondstrue if safe terminateCopyright © 2025. All rights reserved.