@ManagedObject(value="A thread pool") public class QueuedThreadPool extends AbstractLifeCycle implements ThreadPool.SizedThreadPool, Dumpable
AbstractLifeCycle.AbstractLifeCycleListenerThreadPool.SizedThreadPoolLifeCycle.Listener| Constructor and Description |
|---|
QueuedThreadPool() |
QueuedThreadPool(int maxThreads) |
QueuedThreadPool(int maxThreads,
int minThreads) |
QueuedThreadPool(int maxThreads,
int minThreads,
int idleTimeout) |
QueuedThreadPool(int maxThreads,
int minThreads,
int idleTimeout,
BlockingQueue<Runnable> queue) |
QueuedThreadPool(int maxThreads,
int minThreads,
int idleTimeout,
BlockingQueue<Runnable> queue,
ThreadGroup threadGroup) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
doStart() |
protected void |
doStop() |
String |
dump() |
void |
dump(Appendable out,
String indent) |
String |
dumpThread(long id) |
void |
execute(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.
|
String |
getName() |
protected BlockingQueue<Runnable> |
getQueue() |
int |
getQueueSize()
Get the size of the job queue.
|
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 Thread |
newThread(Runnable runnable) |
protected void |
runJob(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(String name) |
void |
setQueue(BlockingQueue<Runnable> queue)
Deprecated.
pass the queue to the constructor instead
|
void |
setThreadsPriority(int priority)
Set the priority of the pool threads.
|
String |
toString() |
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, setStopTimeout, start, stoppublic QueuedThreadPool()
public QueuedThreadPool(@Name(value="maxThreads") int maxThreads, @Name(value="minThreads") int minThreads)
public QueuedThreadPool(@Name(value="maxThreads") int maxThreads, @Name(value="minThreads") int minThreads, @Name(value="idleTimeout") int idleTimeout)
public QueuedThreadPool(@Name(value="maxThreads") int maxThreads, @Name(value="minThreads") int minThreads, @Name(value="idleTimeout") int idleTimeout, @Name(value="queue") BlockingQueue<Runnable> queue)
protected void doStart()
throws Exception
doStart in class AbstractLifeCycleExceptionprotected void doStop()
throws Exception
doStop in class AbstractLifeCycleExceptionpublic 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 setName(String name)
name - Name of this thread pool to use when naming threads.public void setThreadsPriority(int priority)
priority - the new thread priority.@ManagedAttribute(value="maximum time a thread may be idle in ms") public int getIdleTimeout()
setIdleTimeout(int)@ManagedAttribute(value="maximum number of threads in the pool") public int getMaxThreads()
getMaxThreads in interface ThreadPool.SizedThreadPoolsetMaxThreads(int)@ManagedAttribute(value="minimum number of threads in the pool") public int getMinThreads()
getMinThreads in interface ThreadPool.SizedThreadPoolsetMinThreads(int)@ManagedAttribute(value="name of the thread pool") public String getName()
@ManagedAttribute(value="priority of threads in the pool") public int getThreadsPriority()
@ManagedAttribute(value="size of the job queue") public int getQueueSize()
@ManagedAttribute(value="thread pool uses daemon threads") public boolean isDaemon()
Thread.setDaemon(boolean)@ManagedAttribute(value="reports additional details in the dump") public boolean isDetailedDump()
public void setDetailedDump(boolean detailedDump)
@ManagedAttribute(value="threshold at which the pool is low on threads") public int getLowThreadsThreshold()
public void setLowThreadsThreshold(int lowThreadsThreshold)
public void join()
throws InterruptedException
stopped.join in interface ThreadPoolInterruptedException - if thread was interrupted@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@ManagedAttribute(value="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()@ManagedOperation(value="dumps thread pool state") public String dump()
public void dump(Appendable out, String indent) throws IOException
dump in interface DumpableIOExceptionprotected void runJob(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 BlockingQueue<Runnable> getQueue()
@Deprecated public void setQueue(BlockingQueue<Runnable> queue)
queue - the job queue@ManagedOperation(value="interrupts a pool thread") public boolean interruptThread(@Name(value="id") long id)
id - the thread ID to interrupt.@ManagedOperation(value="dumps a pool thread stack") public String dumpThread(@Name(value="id") long id)
id - the thread ID to interrupt.Copyright © 1995-2016 Webtide. All Rights Reserved.