public class DynamicExecutors extends Object
DynamicThreadPoolExecutor
.Modifier and Type | Method and Description |
---|---|
static ThreadFactory |
daemonThreadFactory(String namePrefix)
A priority based thread factory, for all Thread priority constants: Thread.MIN_PRIORITY,
Thread.NORM_PRIORITY, Thread.MAX_PRIORITY;
|
static ExecutorService |
newBlockingThreadPool(int min,
int max,
long keepAliveTime,
int capacity,
long waitTime) |
static ExecutorService |
newBlockingThreadPool(int min,
int max,
long keepAliveTime,
int capacity,
long waitTime,
boolean preStart)
Creates a thread pool similar to that constructed by
newScalingThreadPool(int, int,
long) , but blocks the call to execute if the queue has reached it's capacity, and
all max threads are busy handling requests. |
static ExecutorService |
newBlockingThreadPool(int min,
int max,
long keepAliveTime,
int capacity,
long waitTime,
int priority,
String poolName,
boolean preStart) |
static ExecutorService |
newBlockingThreadPool(int min,
int max,
long keepAliveTime,
int capacity,
long waitTime,
ThreadFactory threadFactory)
Creates a thread pool, same as in
newBlockingThreadPool(int, int, long, int, long) ,
using the provided ThreadFactory to create new threads when needed. |
static FutureExecutorService |
newEventThreadPool(int min,
int max,
long keepAliveTime,
long waitTime,
ThreadFactory threadFactory)
Creates a thread pool, same as in
newScalingThreadPool(int, int, long,
ThreadFactory) , using the provided ThreadFactory to create new threads when needed. |
static ExecutorService |
newScalingThreadPool(int min,
int max,
long keepAliveTime)
Creates a thread pool that creates new threads as needed, but will reuse previously
constructed threads when they are available.
|
static ExecutorService |
newScalingThreadPool(int min,
int max,
long keepAliveTime,
ThreadFactory threadFactory)
Creates a thread pool, same as in
newScalingThreadPool(int, int, long) , using the
provided ThreadFactory to create new threads when needed. |
static ThreadFactory |
priorityThreadFactory(int priority,
String namePrefix)
A priority based thread factory, for all Thread priority constants: Thread.MIN_PRIORITY,
Thread.NORM_PRIORITY, Thread.MAX_PRIORITY;
|
public static ExecutorService newScalingThreadPool(int min, int max, long keepAliveTime)
min
- the number of threads to keep in the pool, even if they are idle.max
- the maximum number of threads to allow in the pool.keepAliveTime
- when the number of threads is greater than the min, this is the maximum
time that excess idle threads will wait for new tasks before terminating
(in milliseconds).public static ExecutorService newScalingThreadPool(int min, int max, long keepAliveTime, ThreadFactory threadFactory)
newScalingThreadPool(int, int, long)
, using the
provided ThreadFactory to create new threads when needed.min
- the number of threads to keep in the pool, even if they are idle.max
- the maximum number of threads to allow in the pool.keepAliveTime
- when the number of threads is greater than the min, this is the maximum
time that excess idle threads will wait for new tasks before terminating
(in milliseconds).threadFactory
- the factory to use when creating new threads.public static ExecutorService newBlockingThreadPool(int min, int max, long keepAliveTime, int capacity, long waitTime)
public static ExecutorService newBlockingThreadPool(int min, int max, long keepAliveTime, int capacity, long waitTime, boolean preStart)
newScalingThreadPool(int, int,
long)
, but blocks the call to execute if the queue has reached it's capacity, and
all max threads are busy handling requests. If the wait time of this queue has
elapsed, a RejectedExecutionException
will be thrown.
min
- the number of threads to keep in the pool, even if they are idle.max
- the maximum number of threads to allow in the pool.keepAliveTime
- when the number of threads is greater than the min, this is the maximum
time that excess idle threads will wait for new tasks before terminating
(in milliseconds).capacity
- the fixed capacity of the underlying queue (resembles backlog).waitTime
- the wait time (in milliseconds) for space to become available in the
queue.preStart
- whether to pre start all core threads in the pool.public static ExecutorService newBlockingThreadPool(int min, int max, long keepAliveTime, int capacity, long waitTime, int priority, String poolName, boolean preStart)
public static ExecutorService newBlockingThreadPool(int min, int max, long keepAliveTime, int capacity, long waitTime, ThreadFactory threadFactory)
newBlockingThreadPool(int, int, long, int, long)
,
using the provided ThreadFactory to create new threads when needed.min
- the number of threads to keep in the pool, even if they are idle.max
- the maximum number of threads to allow in the pool.keepAliveTime
- when the number of threads is greater than the min, this is the maximum
time that excess idle threads will wait for new tasks before terminating
(in milliseconds).capacity
- the fixed capacity of the underlying queue (resembles backlog).waitTime
- the wait time (in milliseconds) for space to become available in the
queue.threadFactory
- the factory to use when creating new threads.public static FutureExecutorService newEventThreadPool(int min, int max, long keepAliveTime, long waitTime, ThreadFactory threadFactory)
newScalingThreadPool(int, int, long,
ThreadFactory)
, using the provided ThreadFactory to create new threads when needed. The
thread pool is backed by a timeout observer which waits for tasks to complete up to the
specified waitTime. If a future task has not completed by this time, a Thread.interrupt()
is invoked.
There are no guarantees beyond best-effort attempts to stop processing actively executing
tasks. For example, typical implementations will cancel via Thread.interrupt()
, so if
any tasks mask or fail to respond to interrupts, they may never terminate.
min
- the number of threads to keep in the pool, even if they are idle.max
- the maximum number of threads to allow in the pool.keepAliveTime
- when the number of threads is greater than the min, this is the maximum
time that excess idle threads will wait for new tasks before terminating
(in milliseconds).waitTime
- the maximum time to wait before interrupting a task.threadFactory
- the factory to use when creating new threads.public static ThreadFactory daemonThreadFactory(String namePrefix)
This factory is used instead of Executers.DefaultThreadFactory to allow manipulation of priority and thread owner name.
namePrefix
- a name prefix for this threadpublic static ThreadFactory priorityThreadFactory(int priority, String namePrefix)
This factory is used instead of Executers.DefaultThreadFactory to allow manipulation of priority and thread owner name.
priority
- The priority to be assigned to each thread; can be either
Thread.MIN_PRIORITY, Thread.NORM_PRIORITY or Thread.MAX_PRIORITY.namePrefix
- a name prefix for this threadCopyright © GigaSpaces.