@ManagedObject(value="A thread pool") public class ExecutorThreadPool extends ContainerLifeCycle implements ThreadPool.SizedThreadPool, TryExecutor
ThreadPool.SizedThreadPool
wrapper around ThreadPoolExecutor
.AbstractLifeCycle.AbstractLifeCycleListener
ThreadPool.SizedThreadPool
TryExecutor.NoTryExecutor
Container.InheritedListener, Container.Listener
LifeCycle.Listener
Modifier and Type | Field and Description |
---|---|
private ThreadPoolBudget |
_budget |
private boolean |
_daemon |
private boolean |
_detailedDump |
private java.util.concurrent.ThreadPoolExecutor |
_executor |
private java.lang.ThreadGroup |
_group |
private int |
_minThreads |
private java.lang.String |
_name |
private int |
_priority |
private int |
_reservedThreads |
private TryExecutor |
_tryExecutor |
FAILED, RUNNING, STARTED, STARTING, STOPPED, STOPPING
NO_TRY
Modifier | Constructor and Description |
---|---|
|
ExecutorThreadPool() |
|
ExecutorThreadPool(int maxThreads) |
|
ExecutorThreadPool(int maxThreads,
int minThreads) |
|
ExecutorThreadPool(int maxThreads,
int minThreads,
java.util.concurrent.BlockingQueue<java.lang.Runnable> queue) |
|
ExecutorThreadPool(java.util.concurrent.ThreadPoolExecutor executor) |
|
ExecutorThreadPool(java.util.concurrent.ThreadPoolExecutor executor,
int reservedThreads) |
private |
ExecutorThreadPool(java.util.concurrent.ThreadPoolExecutor executor,
int minThreads,
int reservedThreads,
java.lang.ThreadGroup group) |
|
ExecutorThreadPool(java.util.concurrent.ThreadPoolExecutor executor,
int reservedThreads,
java.lang.ThreadGroup group) |
Modifier and Type | Method and Description |
---|---|
protected void |
doStart()
Starts the managed lifecycle beans in the order they were added.
|
protected void |
doStop()
Stops the managed lifecycle beans in the reverse order they were added.
|
void |
dump(java.lang.Appendable out,
java.lang.String indent)
Dump this object (and children) into an Appendable using the provided indent after any new lines.
|
void |
execute(java.lang.Runnable command) |
int |
getIdleThreads() |
int |
getIdleTimeout() |
int |
getMaxThreads() |
int |
getMinThreads() |
java.lang.String |
getName() |
int |
getReservedThreads() |
ThreadPoolBudget |
getThreadPoolBudget() |
int |
getThreads() |
int |
getThreadsPriority() |
boolean |
isDaemon() |
boolean |
isDetailedDump() |
boolean |
isLowOnThreads() |
void |
join()
Blocks until the thread pool is
stopped . |
protected java.lang.Thread |
newThread(java.lang.Runnable job) |
void |
setDaemon(boolean daemon) |
void |
setDetailedDump(boolean detailedDump) |
void |
setIdleTimeout(int idleTimeout)
Sets the maximum thread idle time in ms.
|
void |
setMaxThreads(int threads) |
void |
setMinThreads(int threads) |
void |
setName(java.lang.String name) |
void |
setReservedThreads(int reservedThreads)
Sets the number of reserved threads.
|
void |
setThreadsPriority(int priority) |
java.lang.String |
toString() |
boolean |
tryExecute(java.lang.Runnable task)
Attempt to execute a task.
|
addBean, addBean, addBean, addEventListener, addManaged, contains, destroy, dump, dump, dump, dump, dumpBeans, dumpObject, dumpObjects, dumpStdErr, dumpThis, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, setStopTimeout, start, stop, unmanage, updateBean, updateBean, updateBeans
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
asTryExecutor
dumpContainer, dumpIterable, dumpMapEntries, dumpObjects, dumpSelf, named
private final java.util.concurrent.ThreadPoolExecutor _executor
private final ThreadPoolBudget _budget
private final java.lang.ThreadGroup _group
private java.lang.String _name
private int _minThreads
private int _reservedThreads
private TryExecutor _tryExecutor
private int _priority
private boolean _daemon
private boolean _detailedDump
public ExecutorThreadPool()
public ExecutorThreadPool(int maxThreads)
public ExecutorThreadPool(int maxThreads, int minThreads)
public ExecutorThreadPool(int maxThreads, int minThreads, java.util.concurrent.BlockingQueue<java.lang.Runnable> queue)
public ExecutorThreadPool(java.util.concurrent.ThreadPoolExecutor executor)
public ExecutorThreadPool(java.util.concurrent.ThreadPoolExecutor executor, int reservedThreads)
public ExecutorThreadPool(java.util.concurrent.ThreadPoolExecutor executor, int reservedThreads, java.lang.ThreadGroup group)
private ExecutorThreadPool(java.util.concurrent.ThreadPoolExecutor executor, int minThreads, int reservedThreads, java.lang.ThreadGroup group)
@ManagedAttribute(value="name of this thread pool") public java.lang.String getName()
public void setName(java.lang.String name)
name
- the name of this thread pool, used to name threads@ManagedAttribute(value="minimum number of threads in the pool") public int getMinThreads()
getMinThreads
in interface ThreadPool.SizedThreadPool
public void setMinThreads(int threads)
setMinThreads
in interface ThreadPool.SizedThreadPool
threads
- the minimum number of threads@ManagedAttribute(value="maximum number of threads in the pool") public int getMaxThreads()
getMaxThreads
in interface ThreadPool.SizedThreadPool
public void setMaxThreads(int threads)
setMaxThreads
in interface ThreadPool.SizedThreadPool
threads
- the maximum number of threads@ManagedAttribute(value="maximum time a thread may be idle in ms") public int getIdleTimeout()
setIdleTimeout(int)
public void setIdleTimeout(int idleTimeout)
Sets the maximum thread idle time in ms.
Threads that are idle for longer than this period may be stopped.
idleTimeout
- the maximum thread idle time in ms.getIdleTimeout()
@ManagedAttribute(value="the number of reserved threads in the pool") public int getReservedThreads()
setReservedThreads(int)
public void setReservedThreads(int reservedThreads)
reservedThreads
- number of reserved threads or -1 to determine the number heuristicallygetReservedThreads()
public void setThreadsPriority(int priority)
public int getThreadsPriority()
@ManagedAttribute(value="whether this thread pool uses daemon threads") public boolean isDaemon()
setDaemon(boolean)
public void setDaemon(boolean daemon)
daemon
- whether this thread pool uses daemon threadsThread.setDaemon(boolean)
@ManagedAttribute(value="reports additional details in the dump") public boolean isDetailedDump()
public void setDetailedDump(boolean detailedDump)
@ManagedAttribute(value="number of threads in the pool") public int getThreads()
getThreads
in interface ThreadPool
@ManagedAttribute(value="number of idle threads in the pool") public int getIdleThreads()
getIdleThreads
in interface ThreadPool
public void execute(java.lang.Runnable command)
execute
in interface java.util.concurrent.Executor
execute
in interface TryExecutor
public boolean tryExecute(java.lang.Runnable task)
TryExecutor
tryExecute
in interface TryExecutor
task
- The task to be executed@ManagedAttribute(value="thread pool is low on threads", readonly=true) public boolean isLowOnThreads()
isLowOnThreads
in interface ThreadPool
protected void doStart() throws java.lang.Exception
ContainerLifeCycle
doStart
in class ContainerLifeCycle
java.lang.Exception
protected void doStop() throws java.lang.Exception
ContainerLifeCycle
doStop
in class ContainerLifeCycle
java.lang.Exception
public void join() throws java.lang.InterruptedException
ThreadPool
stopped
.join
in interface ThreadPool
java.lang.InterruptedException
- if thread was interruptedpublic ThreadPoolBudget getThreadPoolBudget()
getThreadPoolBudget
in interface ThreadPool.SizedThreadPool
protected java.lang.Thread newThread(java.lang.Runnable job)
public void dump(java.lang.Appendable out, java.lang.String indent) throws java.io.IOException
Dumpable
dump
in interface Dumpable
dump
in class ContainerLifeCycle
out
- The appendable to dump toindent
- The indent to apply after any new lines.java.io.IOException
- if unable to write to Appendablepublic java.lang.String toString()
toString
in class AbstractLifeCycle