@ManagedObject(value="A thread pool with no max bound by default") public class QueuedThreadPool extends AbstractLifeCycle implements ThreadPool.SizedThreadPool, Dumpable
AbstractLifeCycle.AbstractLifeCycleListener
ThreadPool.SizedThreadPool
LifeCycle.Listener
Constructor and Description |
---|
QueuedThreadPool() |
QueuedThreadPool(int maxThreads) |
QueuedThreadPool(int maxThreads,
int minThreads) |
QueuedThreadPool(int maxThreads,
int minThreads,
int maxIdleTimeMs) |
Modifier and Type | Method and Description |
---|---|
boolean |
dispatch(Runnable job) |
protected void |
doStart() |
protected void |
doStop() |
String |
dump() |
void |
dump(Appendable out,
String indent) |
String |
dumpThread(long id) |
void |
execute(Runnable job) |
int |
getIdleThreads() |
int |
getMaxIdleTimeMs()
Get the maximum thread idle time.
|
int |
getMaxQueued() |
int |
getMaxThreads()
Set the maximum number of threads.
|
int |
getMinThreads()
Get the minimum number of threads.
|
String |
getName() |
protected BlockingQueue<Runnable> |
getQueue() |
int |
getThreads() |
int |
getThreadsPriority()
Get the priority of the pool threads.
|
boolean |
interruptThread(long id) |
boolean |
isDaemon()
Delegated to the named or anonymous Pool.
|
boolean |
isDetailedDump() |
boolean |
isLowOnThreads() |
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)
Delegated to the named or anonymous Pool.
|
void |
setDetailedDump(boolean detailedDump) |
void |
setMaxIdleTimeMs(int maxIdleTimeMs)
Set the maximum thread idle time.
|
void |
setMaxQueued(int max) |
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 |
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, stop
public QueuedThreadPool()
public QueuedThreadPool(int maxThreads)
public QueuedThreadPool(int maxThreads, int minThreads)
public QueuedThreadPool(int maxThreads, int minThreads, int maxIdleTimeMs)
protected void doStart() throws Exception
doStart
in class AbstractLifeCycle
Exception
protected void doStop() throws Exception
doStop
in class AbstractLifeCycle
Exception
public void setDaemon(boolean daemon)
public void setMaxIdleTimeMs(int maxIdleTimeMs)
maxIdleTimeMs
- Max idle time in ms.getMaxIdleTimeMs()
public void setMaxThreads(int maxThreads)
setMaxThreads
in interface ThreadPool.SizedThreadPool
maxThreads
- maximum number of threads.getMaxThreads()
public void setMinThreads(int minThreads)
setMinThreads
in interface ThreadPool.SizedThreadPool
minThreads
- minimum number of threadsgetMinThreads()
public void setName(String name)
name
- Name of the BoundedThreadPool to use when naming Threads.public void setThreadsPriority(int priority)
priority
- the new thread priority.public int getMaxQueued()
public void setMaxQueued(int max)
max
- job queue size@ManagedAttribute(value="maximum time a thread may be idle in ms") public int getMaxIdleTimeMs()
setMaxIdleTimeMs(int)
@ManagedAttribute(value="maximum number of threads in the pool") public int getMaxThreads()
getMaxThreads
in interface ThreadPool.SizedThreadPool
setMaxThreads(int)
@ManagedAttribute(value="minimum number of threads in the pool") public int getMinThreads()
getMinThreads
in interface ThreadPool.SizedThreadPool
setMinThreads(int)
@ManagedAttribute(value="name of the thread pool") public String getName()
@ManagedAttribute(value="priority of threads in the pool") public int getThreadsPriority()
@ManagedAttribute(value="thead pool using a daemon thread") public boolean isDaemon()
public boolean isDetailedDump()
public void setDetailedDump(boolean detailedDump)
public boolean dispatch(Runnable job)
dispatch
in interface ThreadPool
public void join() throws InterruptedException
stopped
.join
in interface ThreadPool
InterruptedException
public int getThreads()
getThreads
in interface ThreadPool
public int getIdleThreads()
getIdleThreads
in interface ThreadPool
public boolean isLowOnThreads()
isLowOnThreads
in interface ThreadPool
@ManagedOperation(value="dump thread state") public String dump()
public void dump(Appendable out, String indent) throws IOException
dump
in interface Dumpable
IOException
protected 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()
@ManagedOperation(value="interrupt a pool thread") public boolean interruptThread(@Name(value="id") long id)
id
- The thread ID to interrupt.@ManagedOperation(value="dump a pool thread stack") public String dumpThread(@Name(value="id") long id)
id
- The thread ID to interrupt.Copyright © 1995-2012 Mort Bay Consulting. All Rights Reserved.