|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object
|
+--java.lang.ThreadGroup
|
+--com.go.trove.util.ThreadPool
A ThreadPool contains a collection of re-usable threads. There is a slight performance overhead in creating new threads, and so a ThreadPool can improve performance in systems that create short-lived threads. Pooled threads operate on Runnable targets and return back to the pool when the Runnable.run method exits.
| Constructor Summary | |
ThreadPool(java.lang.String name,
int max)
Create a ThreadPool of daemon threads. |
|
ThreadPool(java.lang.String name,
int max,
boolean daemon)
Create a ThreadPool. |
|
ThreadPool(java.lang.ThreadGroup parent,
java.lang.String name,
int max)
Create a ThreadPool of daemon threads. |
|
ThreadPool(java.lang.ThreadGroup parent,
java.lang.String name,
int max,
boolean daemon)
Create a ThreadPool. |
|
| Method Summary | |
void |
addThreadPoolListener(ThreadPoolListener listener)
|
void |
close()
Will close down all the threads in the pool as they become available. |
void |
close(long timeout)
Will close down all the threads in the pool as they become available. |
java.lang.Thread[] |
getAllThreads()
|
int |
getAvailableCount()
|
long |
getIdleTimeout()
Returns the idle timeout (in milliseconds) for threads to exit. |
int |
getMaximumAllowed()
|
int |
getPooledCount()
|
int |
getPriority()
Returns the initial priority given to each thread in the pool. |
int |
getThreadCount()
|
long |
getTimeout()
Returns the timeout (in milliseconds) for getting threads from the pool. |
boolean |
isClosed()
|
void |
removeThreadPoolListener(ThreadPoolListener listener)
|
void |
setIdleTimeout(long timeout)
Sets the timeout (in milliseconds) for idle threads to exit. |
void |
setPriority(int priority)
Sets the priority given to each thread in the pool. |
void |
setTimeout(long timeout)
Sets the timeout (in milliseconds) for getting threads from the pool or for closing the pool. |
java.lang.Thread |
start(java.lang.Runnable target)
Waits for a Thread to become available and starts a Runnable in it. |
java.lang.Thread |
start(java.lang.Runnable target,
long timeout)
Waits for a Thread to become available and starts a Runnable in it. |
java.lang.Thread |
start(java.lang.Runnable target,
long timeout,
java.lang.String name)
Waits for a Thread to become available and starts a Runnable in it. |
java.lang.Thread |
start(java.lang.Runnable target,
java.lang.String name)
Waits for a Thread to become available and starts a Runnable in it. |
| Methods inherited from class java.lang.ThreadGroup |
activeCount, activeGroupCount, allowThreadSuspension, checkAccess, destroy, enumerate, enumerate, enumerate, enumerate, getMaxPriority, getName, getParent, interrupt, isDaemon, isDestroyed, list, parentOf, resume, setDaemon, setMaxPriority, stop, suspend, toString, uncaughtException |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
public ThreadPool(java.lang.String name,
int max)
throws java.lang.IllegalArgumentException
name - Name of ThreadPoolmax - The maximum allowed number of threadsjava.lang.IllegalArgumentException -
public ThreadPool(java.lang.ThreadGroup parent,
java.lang.String name,
int max)
throws java.lang.IllegalArgumentException
parent - Parent ThreadGroupname - Name of ThreadPoolmax - The maximum allowed number of threadsjava.lang.IllegalArgumentException -
public ThreadPool(java.lang.String name,
int max,
boolean daemon)
throws java.lang.IllegalArgumentException
name - Name of ThreadPoolmax - The maximum allowed number of threadsdaemon - Set to true to create ThreadPool of daemon threadsjava.lang.IllegalArgumentException -
public ThreadPool(java.lang.ThreadGroup parent,
java.lang.String name,
int max,
boolean daemon)
throws java.lang.IllegalArgumentException
parent - Parent ThreadGroupname - Name of ThreadPoolmax - The maximum allowed number of threadsdaemon - Set to true to create ThreadPool of daemon threadsjava.lang.IllegalArgumentException - | Method Detail |
public void setTimeout(long timeout)
public long getTimeout()
public void setIdleTimeout(long timeout)
public long getIdleTimeout()
public void addThreadPoolListener(ThreadPoolListener listener)
public void removeThreadPoolListener(ThreadPoolListener listener)
public int getPriority()
public void setPriority(int priority)
throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException - if priority is out of rangepublic int getMaximumAllowed()
public int getAvailableCount()
public int getPooledCount()
public int getThreadCount()
public java.lang.Thread[] getAllThreads()
public java.lang.Thread start(java.lang.Runnable target)
throws NoThreadException,
java.lang.InterruptedException
target - The Runnable instance that gets started by the returned
thread.NoThreadException - If no thread could be obtained.java.lang.InterruptedException - If interrupted while waiting for a
thread to become available.
public java.lang.Thread start(java.lang.Runnable target,
long timeout)
throws NoThreadException,
java.lang.InterruptedException
target - The Runnable instance that gets started by the returned
thread.timeout - Milliseconds to wait for a thread to become
available. If zero, don't wait at all. If negative, wait forever.NoThreadException - If no thread could be obtained.java.lang.InterruptedException - If interrupted while waiting for a
thread to become available.
public java.lang.Thread start(java.lang.Runnable target,
java.lang.String name)
throws NoThreadException,
java.lang.InterruptedException
target - The Runnable instance that gets started by the returned
thread.name - The name to give the thread.NoThreadException - If no thread could be obtained.java.lang.InterruptedException - If interrupted while waiting for a
thread to become available.
public java.lang.Thread start(java.lang.Runnable target,
long timeout,
java.lang.String name)
throws NoThreadException,
java.lang.InterruptedException
target - The Runnable instance that gets started by the returned
thread.timeout - Milliseconds to wait for a thread to becomename - The name to give the thread.
available. If zero, don't wait at all. If negative, wait forever.NoThreadException - If no thread could be obtained.java.lang.InterruptedException - If interrupted while waiting for a
thread to become available.public boolean isClosed()
public void close()
throws java.lang.InterruptedException
public void close(long timeout)
throws java.lang.InterruptedException
timeout - Milliseconds to wait before unavailable threads
are interrupted. If zero, don't wait at all. If negative, wait forever.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||