public final class ExecutorsX extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
ExecutorsX.DelegatedExecutorService
A wrapper class that exposes only the ExecutorService methods
of an ExecutorService implementation.
|
static class |
ExecutorsX.DelegatedScheduledExecutorService
A wrapper class that exposes only the ScheduledExecutorService
methods of a ScheduledExecutorService implementation.
|
static class |
ExecutorsX.FinalizableDelegatedExecutorService |
| Modifier and Type | Method and Description |
|---|---|
static ExecutorService |
newCachedThreadPool(int maximumPoolSize)
Creates a thread pool that creates new threads as needed, but
will reuse previously constructed threads when they are
available.
|
static ExecutorService |
newCachedThreadPool(int maximumPoolSize,
ThreadFactory threadFactory)
Creates a thread pool that creates new threads as needed, but
will reuse previously constructed threads when they are
available, and uses the provided
ThreadFactory to create new threads when needed.
|
static ExecutorService |
newCachedThreadPool(int maximumPoolSize,
ThreadFactory threadFactory,
RejectedExecutionHandler handler)
Creates a thread pool that creates new threads as needed, but
will reuse previously constructed threads when they are
available, and uses the provided
ThreadFactory to create new threads when needed.
|
static ExecutorService |
newFixedThreadPool(int nThreads,
int queueCapacity)
Creates a thread pool that reuses a fixed number of threads
operating off a shared unbounded queue.
|
static ExecutorService |
newFixedThreadPool(int nThreads,
int queueCapacity,
ThreadFactory threadFactory)
Creates a thread pool that reuses a fixed number of threads
operating off a shared unbounded queue, using the provided
ThreadFactory to create new threads when needed.
|
static ExecutorService |
newFixedThreadPool(int nThreads,
int queueCapacity,
ThreadFactory threadFactory,
RejectedExecutionHandler handler)
Creates a thread pool that reuses a fixed number of threads
operating off a shared unbounded queue, using the provided
ThreadFactory to create new threads when needed.
|
static ScheduledExecutorService |
newScheduledThreadPool(int corePoolSize,
int maximumPoolSize)
Creates a thread pool that can schedule commands to run after a
given delay, or to execute periodically.
|
static ScheduledExecutorService |
newScheduledThreadPool(int corePoolSize,
int maximumPoolSize,
ThreadFactory threadFactory)
Creates a thread pool that can schedule commands to run after a
given delay, or to execute periodically.
|
static ScheduledExecutorService |
newScheduledThreadPool(int corePoolSize,
int maximumPoolSize,
ThreadFactory threadFactory,
RejectedExecutionHandler handler)
Creates a thread pool that can schedule commands to run after a
given delay, or to execute periodically.
|
static ExecutorService |
newSingleThreadExecutor(int queueCapacity)
Creates an Executor that uses a single worker thread operating
off an unbounded queue.
|
static ExecutorService |
newSingleThreadExecutor(int queueCapacity,
ThreadFactory threadFactory)
Creates an Executor that uses a single worker thread operating
off an unbounded queue, and uses the provided ThreadFactory to
create a new thread when needed.
|
static ExecutorService |
newSingleThreadExecutor(int queueCapacity,
ThreadFactory threadFactory,
RejectedExecutionHandler handler)
Creates an Executor that uses a single worker thread operating
off an unbounded queue, and uses the provided ThreadFactory to
create a new thread when needed.
|
static ScheduledExecutorService |
newSingleThreadScheduledExecutor(int maximumPoolSize)
Creates a single-threaded executor that can schedule commands
to run after a given delay, or to execute periodically.
|
static ScheduledExecutorService |
newSingleThreadScheduledExecutor(int maximumPoolSize,
ThreadFactory threadFactory)
Creates a single-threaded executor that can schedule commands
to run after a given delay, or to execute periodically.
|
public static ExecutorService newFixedThreadPool(int nThreads, int queueCapacity)
nThreads threads will be active processing tasks.
If additional tasks are submitted when all threads are active,
they will wait in the queue until a thread is available.
If any thread terminates due to a failure during execution
prior to shutdown, a new one will take its place if needed to
execute subsequent tasks. The threads in the pool will exist
until it is explicitly shutdown.nThreads - the number of threads in the poolqueueCapacity - linked blocking queue capacityIllegalArgumentException - if nThreads <= 0public static ExecutorService newFixedThreadPool(int nThreads, int queueCapacity, ThreadFactory threadFactory)
nThreads threads will be active processing
tasks. If additional tasks are submitted when all threads are
active, they will wait in the queue until a thread is
available. If any thread terminates due to a failure during
execution prior to shutdown, a new one will take its place if
needed to execute subsequent tasks. The threads in the pool will
exist until it is explicitly shutdown.nThreads - the number of threads in the poolqueueCapacity - linked blocking queue capacitythreadFactory - the factory to use when creating new threadsNullPointerException - if threadFactory is nullIllegalArgumentException - if nThreads <= 0public static ExecutorService newFixedThreadPool(int nThreads, int queueCapacity, ThreadFactory threadFactory, RejectedExecutionHandler handler)
nThreads threads will be active processing
tasks. If additional tasks are submitted when all threads are
active, they will wait in the queue until a thread is
available. If any thread terminates due to a failure during
execution prior to shutdown, a new one will take its place if
needed to execute subsequent tasks. The threads in the pool will
exist until it is explicitly shutdown.nThreads - the number of threads in the poolqueueCapacity - linked blocking queue capacitythreadFactory - the factory to use when creating new threadshandler - the handler to use when execution is blocked
because the thread bounds and queue capacities are reachedNullPointerException - if threadFactory is nullIllegalArgumentException - if nThreads <= 0public static ExecutorService newSingleThreadExecutor(int queueCapacity)
newFixedThreadPool(1) the returned executor is
guaranteed not to be reconfigurable to use additional threads.queueCapacity - linked blocking queue capacitypublic static ExecutorService newSingleThreadExecutor(int queueCapacity, ThreadFactory threadFactory)
newFixedThreadPool(1, threadFactory) the
returned executor is guaranteed not to be reconfigurable to use
additional threads.queueCapacity - linked blocking queue capacitythreadFactory - the factory to use when creating new
threadsNullPointerException - if threadFactory is nullpublic static ExecutorService newSingleThreadExecutor(int queueCapacity, ThreadFactory threadFactory, RejectedExecutionHandler handler)
newFixedThreadPool(1, threadFactory) the
returned executor is guaranteed not to be reconfigurable to use
additional threads.queueCapacity - linked blocking queue capacitythreadFactory - the factory to use when creating new
threadshandler - the handler to use when execution is blocked
because the thread bounds and queue capacities are reachedNullPointerException - if threadFactory is nullpublic static ExecutorService newCachedThreadPool(int maximumPoolSize)
execute will reuse previously constructed
threads if available. If no existing thread is available, a new
thread will be created and added to the pool. Threads that have
not been used for sixty seconds are terminated and removed from
the cache. Thus, a pool that remains idle for long enough will
not consume any resources. Note that pools with similar
properties but different details (for example, timeout parameters)
may be created using ThreadPoolExecutor constructors.maximumPoolSize - max pool sizepublic static ExecutorService newCachedThreadPool(int maximumPoolSize, ThreadFactory threadFactory)
maximumPoolSize - max pool sizethreadFactory - the factory to use when creating new threadsNullPointerException - if threadFactory is nullpublic static ExecutorService newCachedThreadPool(int maximumPoolSize, ThreadFactory threadFactory, RejectedExecutionHandler handler)
maximumPoolSize - max pool sizethreadFactory - the factory to use when creating new threadshandler - the handler to use when execution is blocked
because the thread bounds and queue capacities are reachedNullPointerException - if threadFactory is nullpublic static ScheduledExecutorService newSingleThreadScheduledExecutor(int maximumPoolSize)
newScheduledThreadPool(1) the returned executor is
guaranteed not to be reconfigurable to use additional threads.maximumPoolSize - max pool sizepublic static ScheduledExecutorService newSingleThreadScheduledExecutor(int maximumPoolSize, ThreadFactory threadFactory)
newScheduledThreadPool(1, threadFactory)
the returned executor is guaranteed not to be reconfigurable to
use additional threads.maximumPoolSize - max pool sizethreadFactory - the factory to use when creating new
threadsNullPointerException - if threadFactory is nullpublic static ScheduledExecutorService newScheduledThreadPool(int corePoolSize, int maximumPoolSize)
corePoolSize - the number of threads to keep in the pool,
even if they are idlemaximumPoolSize - max pool sizeIllegalArgumentException - if corePoolSize < 0public static ScheduledExecutorService newScheduledThreadPool(int corePoolSize, int maximumPoolSize, ThreadFactory threadFactory)
corePoolSize - the number of threads to keep in the pool,
even if they are idlemaximumPoolSize - max pool sizethreadFactory - the factory to use when the executor
creates a new threadIllegalArgumentException - if corePoolSize < 0NullPointerException - if threadFactory is nullpublic static ScheduledExecutorService newScheduledThreadPool(int corePoolSize, int maximumPoolSize, ThreadFactory threadFactory, RejectedExecutionHandler handler)
corePoolSize - the number of threads to keep in the pool,
even if they are idlemaximumPoolSize - max pool sizethreadFactory - the factory to use when the executor
creates a new threadhandler - the handler to use when execution is blocked
because the thread bounds and queue capacities are reachedIllegalArgumentException - if corePoolSize < 0NullPointerException - if threadFactory is nullCopyright © 2021. All rights reserved.