public class TaskExecutors extends Object
Executors utility class that returns various useful implementations
of TaskExecutorService instead of standard ExecutorService.| Modifier and Type | Method and Description |
|---|---|
static TaskExecutorService |
adapt(ExecutorService executorService) |
static TaskExecutorService |
newCachedThreadPool()
Creates a thread pool that creates new threads as needed, but will reuse
previously constructed threads when they are available.
|
static TaskExecutorService |
newCachedThreadPool(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 TaskExecutorService |
newFixedThreadPool(int nThreads)
Creates a thread pool that reuses a fixed number of threads operating off
a shared unbounded queue.
|
static TaskExecutorService |
newFixedThreadPool(int nThreads,
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 TaskExecutorService |
newSingleThreadExecutor()
Creates an Executor that uses a single worker thread operating off an
unbounded queue.
|
static TaskExecutorService |
newSingleThreadExecutor(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 ThreadFactoryBuilder |
newThreadFactory() |
static ThreadGroupBuilder |
newThreadGroup() |
public static ThreadFactoryBuilder newThreadFactory()
public static ThreadGroupBuilder newThreadGroup()
public static TaskExecutorService newFixedThreadPool(int nThreads)
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 poolIllegalArgumentException - if nThreads <= 0public static TaskExecutorService newFixedThreadPool(int nThreads, 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 poolthreadFactory - the factory to use when creating new threadsNullPointerException - if threadFactory is nullIllegalArgumentException - if nThreads <= 0public static TaskExecutorService newCachedThreadPool()
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.public static TaskExecutorService newCachedThreadPool(ThreadFactory threadFactory)
threadFactory - the factory to use when creating new threadsNullPointerException - if threadFactory is nullpublic static TaskExecutorService newSingleThreadExecutor()
newFixedThreadPool(1)
the returned executor is guaranteed not to be reconfigurable to use
additional threads.public static TaskExecutorService newSingleThreadExecutor(ThreadFactory threadFactory)
newFixedThreadPool(1, threadFactory) the returned executor is
guaranteed not to be reconfigurable to use additional threads.threadFactory - the factory to use when creating new threadsNullPointerException - if threadFactory is nullpublic static TaskExecutorService adapt(ExecutorService executorService)
Copyright © 2021. All rights reserved.