public final class ThreadPoolUtil extends Object
ThreadPoolExecutor and
ScheduledThreadPoolExecutor.| Modifier and Type | Class and Description |
|---|---|
static class |
ThreadPoolUtil.PoolBuilder |
static class |
ThreadPoolUtil.ScheduledPoolBuilder |
| Modifier and Type | Method and Description |
|---|---|
static ThreadPoolUtil.PoolBuilder |
newBuilder() |
static ThreadPoolUtil.ScheduledPoolBuilder |
newScheduledBuilder() |
static ScheduledThreadPoolExecutor |
newScheduledThreadPool(String poolName,
boolean enableMetric,
int coreThreads,
ThreadFactory threadFactory,
RejectedExecutionHandler rejectedHandler)
Creates a new ScheduledThreadPoolExecutor with the given
initial parameters.
|
static ThreadPoolExecutor |
newThreadPool(String poolName,
boolean enableMetric,
int coreThreads,
int maximumThreads,
long keepAliveSeconds,
BlockingQueue<Runnable> workQueue,
ThreadFactory threadFactory,
RejectedExecutionHandler rejectedHandler)
Creates a new
MetricThreadPoolExecutor or LogThreadPoolExecutor
with the given initial parameters. |
public static ThreadPoolUtil.PoolBuilder newBuilder()
public static ThreadPoolUtil.ScheduledPoolBuilder newScheduledBuilder()
public static ThreadPoolExecutor newThreadPool(String poolName, boolean enableMetric, int coreThreads, int maximumThreads, long keepAliveSeconds, BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory, RejectedExecutionHandler rejectedHandler)
MetricThreadPoolExecutor or LogThreadPoolExecutor
with the given initial parameters.poolName - the name of the thread poolenableMetric - if metric is enabledcoreThreads - the number of threads to keep in the pool, even if they are
idle, unless allowCoreThreadTimeOut is set.maximumThreads - the maximum number of threads to allow in the poolkeepAliveSeconds - when the number of threads is greater than the core, this
is the maximum time (seconds) that excess idle threads will
wait for new tasks before terminating.workQueue - the queue to use for holding tasks before they are executed.
This queue will hold only the Runnable tasks submitted
by the execute method.threadFactory - the factory to use when the executor creates a new threadrejectedHandler - the handler to use when execution is blocked because the
thread bounds and queue capacities are reachedIllegalArgumentException - if one of the following holds:corePoolSize < 0keepAliveSeconds < 0maximumPoolSize <= 0maximumPoolSize < corePoolSizeNullPointerException - if workQueue
or threadFactory or handler is nullpublic static ScheduledThreadPoolExecutor newScheduledThreadPool(String poolName, boolean enableMetric, int coreThreads, ThreadFactory threadFactory, RejectedExecutionHandler rejectedHandler)
poolName - the name of the thread poolenableMetric - if metric is enabledcoreThreads - the number of threads to keep in the pool, even if they are
idle, unless allowCoreThreadTimeOut is set.threadFactory - the factory to use when the executor
creates a new threadrejectedHandler - the handler to use when execution is blocked because the
thread bounds and queue capacities are reachedIllegalArgumentException - if corePoolSize < 0NullPointerException - if threadFactory or
handler is nullCopyright © 2023. All rights reserved.