public final class SpecialExecutors extends Object
ExecutorService
instances with specific configurations.Modifier and Type | Method and Description |
---|---|
static ExecutorService |
newBlockingBoundedCachedThreadPool(int maximumPoolSize,
int maximumQueueSize,
String threadPrefix,
Class<?> loggerIdentity)
Creates an ExecutorService similar to
newBoundedCachedThreadPool(int, int, java.lang.String, java.lang.Class<?>) except that it
handles rejected tasks by running them in the same thread as the caller. |
static ExecutorService |
newBlockingBoundedFastThreadPool(int maximumPoolSize,
int maximumQueueSize,
String threadPrefix,
Class<?> loggerIdentity)
Creates an ExecutorService similar to
newBoundedFastThreadPool(int, int, java.lang.String, java.lang.Class<?>) except that it
handles rejected tasks by running them in the same thread as the caller. |
static ExecutorService |
newBoundedCachedThreadPool(int maximumPoolSize,
int maximumQueueSize,
String threadPrefix,
Class<?> loggerIdentity)
Creates an ExecutorService with a specified bounded queue capacity that favors reusing
previously constructed threads, when they are available, over creating new threads.
|
static ExecutorService |
newBoundedFastThreadPool(int maximumPoolSize,
int maximumQueueSize,
String threadPrefix,
Class<?> loggerIdentity)
Creates an ExecutorService with a specified bounded queue capacity that favors creating new
threads over queuing, as the former is faster, so threads will only be reused when the thread
limit is exceeded and tasks are queued.
|
static ExecutorService |
newBoundedSingleThreadExecutor(int maximumQueueSize,
String threadPrefix,
Class<?> loggerIdentity)
Creates an ExecutorService that uses a single worker thread operating off a bounded queue
with the specified capacity.
|
public static ExecutorService newBoundedFastThreadPool(int maximumPoolSize, int maximumQueueSize, String threadPrefix, Class<?> loggerIdentity)
For example, if the maximum number of threads is 100 and 100 short-lived tasks are submitted within say 10 seconds, then 100 threads will be created and used - previously constructed idle threads will not be reused. This provides the fastest execution of the 100 tasks at the expense of memory and thread resource overhead. Therefore it is advisable to specify a relatively small thread limit (probably no more than 50).
Threads that have not been used for 15 seconds are terminated and removed from the pool. Thus, a pool that remains idle for long enough will not consume any resources.
If you need an executor with less memory and thread resource overhead where slower execution
time is acceptable, consider using newBoundedCachedThreadPool(int, int, java.lang.String, java.lang.Class<?>)
.
maximumPoolSize
- the maximum number of threads to allow in the pool. Threads will terminate after
being idle for 15 seconds.maximumQueueSize
- the capacity of the queue.threadPrefix
- the name prefix for threads created by this executor.loggerIdentity
- the class to use as logger name for logging uncaught exceptions from the threads.public static ExecutorService newBlockingBoundedFastThreadPool(int maximumPoolSize, int maximumQueueSize, String threadPrefix, Class<?> loggerIdentity)
newBoundedFastThreadPool(int, int, java.lang.String, java.lang.Class<?>)
except that it
handles rejected tasks by running them in the same thread as the caller. Therefore if the
queue is full, the caller submitting the task will be blocked until the task completes. In
this manner, tasks are never rejected.maximumPoolSize
- the maximum number of threads to allow in the pool. Threads will terminate after
being idle for 15 seconds.maximumQueueSize
- the capacity of the queue.threadPrefix
- the name prefix for threads created by this executor.loggerIdentity
- the class to use as logger name for logging uncaught exceptions from the threads.public static ExecutorService newBoundedCachedThreadPool(int maximumPoolSize, int maximumQueueSize, String threadPrefix, Class<?> loggerIdentity)
Threads that have not been used for sixty seconds are terminated and removed from the pool. Thus, a pool that remains idle for long enough will not consume any resources.
By reusing threads when possible, this executor optimizes for reduced memory and thread resource overhead at the expense of execution time.
If you need an executor with faster execution time where increased memory and thread resource
overhead is acceptable, consider using newBoundedFastThreadPool(int, int, java.lang.String, java.lang.Class<?>)
.
maximumPoolSize
- the maximum number of threads to allow in the pool. Threads will terminate after
being idle for 60 seconds.maximumQueueSize
- the capacity of the queue.threadPrefix
- the name prefix for threads created by this executor.public static ExecutorService newBlockingBoundedCachedThreadPool(int maximumPoolSize, int maximumQueueSize, String threadPrefix, Class<?> loggerIdentity)
newBoundedCachedThreadPool(int, int, java.lang.String, java.lang.Class<?>)
except that it
handles rejected tasks by running them in the same thread as the caller. Therefore if the
queue is full, the caller submitting the task will be blocked until the task completes. In
this manner, tasks are never rejected.maximumPoolSize
- the maximum number of threads to allow in the pool. Threads will terminate after
being idle for 60 seconds.maximumQueueSize
- the capacity of the queue.threadPrefix
- the name prefix for threads created by this executor.public static ExecutorService newBoundedSingleThreadExecutor(int maximumQueueSize, String threadPrefix, Class<?> loggerIdentity)
maximumQueueSize
- the capacity of the queue.threadPrefix
- the name prefix for the thread created by this executor.loggerIdentity
- the class to use as logger name for logging uncaught exceptions from the threads.Copyright © 2019 OpenDaylight. All rights reserved.