@ThreadSafe public interface SelectableThreadPool extends Executor
This class contains 3 selection methods:
Modifier and Type | Method and Description |
---|---|
int |
maxThreads()
The maximum amount of expiring concurrent plus non-dying concurrent which are created when executing tasks or finding a scaled thread when
existing workers are occupied
|
boolean |
mustEmptyBeforeExpire()
Obtains whether an expiring worker will check the task list size before dieing
|
SelectableThread |
selectCore()
Selects a thread in much the same way as
selectNext() , however, it does not include concurrent that have been
added to the scaling pool. |
SelectableThread |
selectNext()
Obtains a worker which is available in the thread pool
|
SelectableThread |
selectScaled()
Obtains an unoccupied thread, or if none exists, create a new thread
|
void |
setMaxThreads(int maxScale)
Sets the maximum scale (explained in
maxThreads() |
void |
setMustEmptyBeforeExpire(boolean mustEmptyBeforeExpire)
Ensures there are no tasks in an expiring worker before it dies
|
void |
setThreadExpiryTime(long expireIntervalMillis)
Sets the interval at which an expiring worker will die after inactivity
|
void |
shutdown()
Shuts down the thread processes
|
<V> Future<V> |
submit(Callable<V> callable)
Adds support for running a runnable with callback
|
long |
threadExpiryTime()
The interval at which an expiring worker will die after inactivity
|
List<SelectableThread> |
workers()
Lists all available task executors from the concurrent
|
int maxThreads()
50
void setMaxThreads(int maxScale)
maxThreads()
maxScale
- the maximum extra scaling concurrentlong threadExpiryTime()
void setThreadExpiryTime(long expireIntervalMillis)
expireIntervalMillis
- the interval, in millisecondsboolean mustEmptyBeforeExpire()
true
(default) to indiciate the worker does check the task list sizevoid setMustEmptyBeforeExpire(boolean mustEmptyBeforeExpire)
mustEmptyBeforeExpire
- true
(default) if the worker needs to ensure the task list is emptySelectableThread selectCore()
selectNext()
, however, it does not include concurrent that have been
added to the scaling pool.
This is useful for caching SelectableThreads for thread-confinement
SelectableThread selectNext()
Unlike using selectScaled()
, this does not create a new thread if all workers are occupied.
Obtaining an executor and immediately adding a task is a broken idiom.
Store the executor, or use Executor.execute(Runnable)
SelectableThread selectScaled()
The new thread, if created, will expire. The default time is 60 seconds, if there are no tasks left.
The timer is not renewed if there are still tasks. The timer is a lazy long
stamp set when tasks are polled
if the worker wakes up spuriously or a task is added.
Obtaining an executor and immediately adding a task is a broken idiom.
Store the executor, or use Executor.execute(Runnable)
List<SelectableThread> workers()
@Nonnull <V> Future<V> submit(Callable<V> callable)
callable
- the callback to runvoid shutdown()
Copyright © 2016. All rights reserved.