java.util.concurrent.Executor, Container, Destroyable, Dumpable, LifeCycle, ThreadPool, ThreadPool.SizedThreadPool, TryExecutorMonitoredQueuedThreadPool@ManagedObject("A thread pool") public class QueuedThreadPool extends ContainerLifeCycle implements ThreadPool.SizedThreadPool, Dumpable, TryExecutor
AbstractLifeCycle.AbstractLifeCycleListenerContainer.InheritedListener, Container.ListenerLifeCycle.ListenerThreadPool.SizedThreadPoolTryExecutor.NoTryExecutorFAILED, RUNNING, STARTED, STARTING, STOPPED, STOPPINGNO_TRY| Constructor | Description |
|---|---|
QueuedThreadPool() |
|
QueuedThreadPool(int maxThreads) |
|
QueuedThreadPool(int maxThreads,
int minThreads) |
|
QueuedThreadPool(int maxThreads,
int minThreads,
int idleTimeout) |
|
QueuedThreadPool(int maxThreads,
int minThreads,
int idleTimeout,
int reservedThreads,
java.util.concurrent.BlockingQueue<java.lang.Runnable> queue,
java.lang.ThreadGroup threadGroup) |
|
QueuedThreadPool(int maxThreads,
int minThreads,
int idleTimeout,
java.util.concurrent.BlockingQueue<java.lang.Runnable> queue) |
|
QueuedThreadPool(int maxThreads,
int minThreads,
int idleTimeout,
java.util.concurrent.BlockingQueue<java.lang.Runnable> queue,
java.lang.ThreadGroup threadGroup) |
| Modifier and Type | Method | 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) |
|
java.lang.String |
dumpThread(long id) |
|
void |
execute(java.lang.Runnable job) |
|
int |
getBusyThreads() |
|
int |
getIdleThreads() |
|
int |
getIdleTimeout() |
Get the maximum thread idle time.
|
int |
getLowThreadsThreshold() |
|
int |
getMaxThreads() |
Get the maximum number of threads.
|
int |
getMinThreads() |
Get the minimum number of threads.
|
java.lang.String |
getName() |
|
protected java.util.concurrent.BlockingQueue<java.lang.Runnable> |
getQueue() |
|
int |
getQueueSize() |
Get the size of the job queue.
|
int |
getReservedThreads() |
Get the number of reserved threads.
|
ThreadPoolBudget |
getThreadPoolBudget() |
|
int |
getThreads() |
|
int |
getThreadsPriority() |
Get the priority of the pool threads.
|
boolean |
interruptThread(long id) |
|
boolean |
isDaemon() |
|
boolean |
isDetailedDump() |
|
boolean |
isLowOnThreads() |
Returns whether this thread pool is low on threads.
|
void |
join() |
Blocks until the thread pool is
stopped. |
protected java.lang.Thread |
newThread(java.lang.Runnable runnable) |
|
protected void |
removeThread(java.lang.Thread thread) |
|
protected void |
runJob(java.lang.Runnable job) |
Runs the given job in the
current thread. |
void |
setDaemon(boolean daemon) |
Thread Pool should use Daemon Threading.
|
void |
setDetailedDump(boolean detailedDump) |
|
void |
setIdleTimeout(int idleTimeout) |
Set the maximum thread idle time.
|
void |
setLowThreadsThreshold(int lowThreadsThreshold) |
|
void |
setMaxThreads(int maxThreads) |
Set the maximum number of threads.
|
void |
setMinThreads(int minThreads) |
Set the minimum number of threads.
|
void |
setName(java.lang.String name) |
|
void |
setQueue(java.util.concurrent.BlockingQueue<java.lang.Runnable> queue) |
Deprecated.
pass the queue to the constructor instead
|
void |
setReservedThreads(int reservedThreads) |
Set the number of reserved threads.
|
void |
setThreadPoolBudget(ThreadPoolBudget budget) |
|
void |
setThreadsPriority(int priority) |
Set the priority of the pool threads.
|
java.lang.String |
toString() |
|
boolean |
tryExecute(java.lang.Runnable task) |
Attempt to execute a task.
|
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stopaddBean, addBean, addBean, addEventListener, addManaged, contains, destroy, dump, dump, dump, dump, dumpBeans, dumpObject, dumpStdErr, dumpThis, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, isManaged, manage, removeBean, removeBeans, removeEventListener, setBeans, setStopTimeout, start, stop, unmanage, updateBean, updateBean, updateBeansclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitasTryExecutorpublic QueuedThreadPool()
public QueuedThreadPool(@Name("maxThreads") int maxThreads)
public QueuedThreadPool(@Name("maxThreads") int maxThreads, @Name("minThreads") int minThreads)
public QueuedThreadPool(@Name("maxThreads") int maxThreads, @Name("minThreads") int minThreads, @Name("idleTimeout") int idleTimeout)
public QueuedThreadPool(@Name("maxThreads") int maxThreads, @Name("minThreads") int minThreads, @Name("idleTimeout") int idleTimeout, @Name("queue") java.util.concurrent.BlockingQueue<java.lang.Runnable> queue)
public QueuedThreadPool(@Name("maxThreads") int maxThreads, @Name("minThreads") int minThreads, @Name("idleTimeout") int idleTimeout, @Name("queue") java.util.concurrent.BlockingQueue<java.lang.Runnable> queue, @Name("threadGroup") java.lang.ThreadGroup threadGroup)
public QueuedThreadPool(@Name("maxThreads") int maxThreads, @Name("minThreads") int minThreads, @Name("idleTimeout") int idleTimeout, @Name("reservedThreads") int reservedThreads, @Name("queue") java.util.concurrent.BlockingQueue<java.lang.Runnable> queue, @Name("threadGroup") java.lang.ThreadGroup threadGroup)
public ThreadPoolBudget getThreadPoolBudget()
getThreadPoolBudget in interface ThreadPool.SizedThreadPoolpublic void setThreadPoolBudget(ThreadPoolBudget budget)
protected void doStart()
throws java.lang.Exception
ContainerLifeCycledoStart in class ContainerLifeCyclejava.lang.Exceptionprotected void doStop()
throws java.lang.Exception
ContainerLifeCycledoStop in class ContainerLifeCyclejava.lang.Exceptionpublic void setDaemon(boolean daemon)
daemon - true to enable delegationThread.setDaemon(boolean)public void setIdleTimeout(int idleTimeout)
idleTimeout - Max idle time in ms.getIdleTimeout()public void setMaxThreads(int maxThreads)
setMaxThreads in interface ThreadPool.SizedThreadPoolmaxThreads - maximum number of threads.getMaxThreads()public void setMinThreads(int minThreads)
setMinThreads in interface ThreadPool.SizedThreadPoolminThreads - minimum number of threadsgetMinThreads()public void setReservedThreads(int reservedThreads)
reservedThreads - number of reserved threads or -1 for heuristically determinedgetReservedThreads()public void setName(java.lang.String name)
name - Name of this thread pool to use when naming threads.public void setThreadsPriority(int priority)
priority - the new thread priority.@ManagedAttribute("maximum time a thread may be idle in ms") public int getIdleTimeout()
setIdleTimeout(int)@ManagedAttribute("maximum number of threads in the pool") public int getMaxThreads()
getMaxThreads in interface ThreadPool.SizedThreadPoolsetMaxThreads(int)@ManagedAttribute("minimum number of threads in the pool") public int getMinThreads()
getMinThreads in interface ThreadPool.SizedThreadPoolsetMinThreads(int)@ManagedAttribute("the number of reserved threads in the pool") public int getReservedThreads()
setReservedThreads(int)@ManagedAttribute("name of the thread pool") public java.lang.String getName()
@ManagedAttribute("priority of threads in the pool") public int getThreadsPriority()
@ManagedAttribute("size of the job queue") public int getQueueSize()
@ManagedAttribute("thread pool uses daemon threads") public boolean isDaemon()
Thread.setDaemon(boolean)@ManagedAttribute("reports additional details in the dump") public boolean isDetailedDump()
public void setDetailedDump(boolean detailedDump)
@ManagedAttribute("threshold at which the pool is low on threads") public int getLowThreadsThreshold()
public void setLowThreadsThreshold(int lowThreadsThreshold)
public void execute(java.lang.Runnable job)
execute in interface java.util.concurrent.Executorexecute in interface TryExecutorpublic boolean tryExecute(java.lang.Runnable task)
TryExecutortryExecute in interface TryExecutortask - The task to be executedpublic void join()
throws java.lang.InterruptedException
stopped.join in interface ThreadPooljava.lang.InterruptedException - if thread was interrupted@ManagedAttribute("number of threads in the pool") public int getThreads()
getThreads in interface ThreadPool@ManagedAttribute("number of idle threads in the pool") public int getIdleThreads()
getIdleThreads in interface ThreadPool@ManagedAttribute("number of busy threads in the pool") public int getBusyThreads()
@ManagedAttribute(value="thread pool is low on threads", readonly=true) public boolean isLowOnThreads()
Returns whether this thread pool is low on threads.
The current formula is:
maxThreads - threads + idleThreads - queueSize <= lowThreadsThreshold
isLowOnThreads in interface ThreadPoolgetLowThreadsThreshold()protected java.lang.Thread newThread(java.lang.Runnable runnable)
protected void removeThread(java.lang.Thread thread)
public void dump(java.lang.Appendable out,
java.lang.String indent)
throws java.io.IOException
dump in interface Dumpabledump in class ContainerLifeCyclejava.io.IOExceptionpublic java.lang.String toString()
toString in class AbstractLifeCycleprotected void runJob(java.lang.Runnable job)
Runs the given job in the current thread.
Subclasses may override to perform pre/post actions before/after the job is run.
job - the job to runprotected java.util.concurrent.BlockingQueue<java.lang.Runnable> getQueue()
@Deprecated public void setQueue(java.util.concurrent.BlockingQueue<java.lang.Runnable> queue)
queue - the job queue@ManagedOperation("interrupts a pool thread") public boolean interruptThread(@Name("id") long id)
id - the thread ID to interrupt.@ManagedOperation("dumps a pool thread stack") public java.lang.String dumpThread(@Name("id") long id)
id - the thread ID to interrupt.Copyright © 1995–2018 Webtide. All rights reserved.