java.util.concurrent.Executor, LifeCycle@ManagedObject("A pool for reserved threads") public class ReservedThreadExecutor extends AbstractLifeCycle implements java.util.concurrent.Executor
Calls to execute(Runnable) on a ReservedThreadExecutor will either succeed
with a Thread immediately being assigned the Runnable task, or fail if no Thread is
available. Threads are preallocated up to the capacity from a wrapped Executor.
AbstractLifeCycle.AbstractLifeCycleListenerLifeCycle.ListenerFAILED, RUNNING, STARTED, STARTING, STOP_ON_FAILURE, STOPPED, STOPPING| Constructor | Description |
|---|---|
ReservedThreadExecutor(java.util.concurrent.Executor executor) |
|
ReservedThreadExecutor(java.util.concurrent.Executor executor,
int capacity) |
| Modifier and Type | Method | Description |
|---|---|---|
void |
doStop() |
|
void |
execute(java.lang.Runnable task) |
|
int |
getAvailable() |
|
int |
getCapacity() |
|
java.util.concurrent.Executor |
getExecutor() |
|
int |
getPending() |
|
java.lang.String |
toString() |
|
boolean |
tryExecute(java.lang.Runnable task) |
addLifeCycleListener, doStart, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, setStopTimeout, start, stoppublic ReservedThreadExecutor(java.util.concurrent.Executor executor)
public ReservedThreadExecutor(java.util.concurrent.Executor executor,
int capacity)
executor - The executor to use to obtain threadscapacity - The number of threads to preallocate. If less than 0 then capacity
is calculated based on a heuristic from the number of available processors and
thread pool size.public java.util.concurrent.Executor getExecutor()
@ManagedAttribute(value="max number of reserved threads", readonly=true) public int getCapacity()
@ManagedAttribute(value="available reserved threads", readonly=true) public int getAvailable()
@ManagedAttribute(value="pending reserved threads", readonly=true) public int getPending()
public void doStop()
throws java.lang.Exception
doStop in class AbstractLifeCyclejava.lang.Exceptionpublic void execute(java.lang.Runnable task)
throws java.util.concurrent.RejectedExecutionException
execute in interface java.util.concurrent.Executorjava.util.concurrent.RejectedExecutionExceptionpublic boolean tryExecute(java.lang.Runnable task)
task - The task to runpublic java.lang.String toString()
toString in class java.lang.ObjectCopyright © 1995–2017 Webtide. All rights reserved.