|
foundry-0.9.1 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.lang.ThreadGroup | +--foundry.threads.ThreadPool
A ThreadGroup
that pools ThreadPool.PooledThread
s. Substantial
portions of this class include software developed by GO.com
(http://opensource.go.com/); those portions are governed by the
Tea Software
License, Version 1.0.
Inner Class Summary | |
private class |
ThreadPool.PooledThread
|
Field Summary | |
private int |
active
The number of active ThreadPool.PooledThread s in this
ThreadPool . |
private long |
idleTimeout
The number of milliseconds that ThreadPool.PooledThread s in this
ThreadPool should wait before aging off. |
private boolean |
isClosed
A flag indicating whether this ThreadPool is closed. |
private boolean |
isDaemon
A flag indicating whether new ThreadPool.PooledThread s in this
ThreadPool should be created as daemon ThreadPool.PooledThread s. |
private Collection |
listeners
A Collection of ThreadPoolListener s that are
alerted when ThreadPool.PooledThread s become available and leave this
ThreadPool . |
private int |
max
The maximum number of ThreadPool.PooledThread s allowed. |
private LinkedList |
pool
The pool itself; a LinkedList of ThreadPool.PooledThread s that
are idling and ready to perform a job. |
private int |
priority
The priority to be given to new ThreadPool.PooledThread s in this
ThreadPool . |
private static int |
threadID
The number that will be used in new ThreadPool.PooledThread names. |
private long |
timeout
The number of milliseconds to wait for getting ThreadPool.PooledThread s
out of this ThreadPool . |
Fields inherited from class java.lang.ThreadGroup |
daemon, destroyed, groups, maxPriority, name, ngroups, nthreads, parent, threads, vmAllowSuspension |
Constructor Summary | |
ThreadPool(String name,
int max)
Creates a ThreadPool of daemon ThreadPool.PooledThread s. |
|
ThreadPool(String name,
int max,
boolean isDaemon)
Creates a ThreadPool . |
|
ThreadPool(ThreadGroup parent,
String name,
int max)
Creates a ThreadPool of daemon ThreadPool.PooledThread s. |
|
ThreadPool(ThreadGroup parent,
String name,
int max,
boolean isDaemon)
Creates a ThreadPool . |
Method Summary | |
void |
addThreadPoolListener(ThreadPoolListener listener)
|
void |
close()
Closes down all the ThreadPool.PooledThread s in this
ThreadPool as they become available. |
void |
close(long timeout)
Closes down all the ThreadPool.PooledThread s in this
ThreadPool as they become available. |
private void |
ensureOpen()
|
Thread[] |
getAllThreads()
|
int |
getAvailableCount()
|
long |
getIdleTimeout()
Returns the idle timeout (in milliseconds) for ThreadPool.PooledThread s to
exit. |
int |
getMaximumAllowed()
|
int |
getPooledCount()
|
int |
getPriority()
Returns the initial priority given to each thread in this ThreadPool . |
int |
getThreadCount()
|
long |
getTimeout()
Returns the timeout (in milliseconds) for getting ThreadPool.PooledThread s
from this ThreadPool . |
private void |
init(int max,
boolean isDaemon)
Initializes this ThreadPool so that it will permit
only the supplied number of ThreadPool.PooledThread s to exist. |
boolean |
isClosed()
|
void |
removeThreadPoolListener(ThreadPoolListener listener)
|
void |
setIdleTimeout(long timeout)
Sets the timeout (in milliseconds) for idle ThreadPool.PooledThread s to
exit. |
void |
setPriority(int priority)
Sets the priority given to each thread in this ThreadPool . |
void |
setTimeout(long timeout)
Sets the timeout (in milliseconds) for getting ThreadPool.PooledThread s
from this ThreadPool or for closing this
ThreadPool . |
private Thread[] |
sort(Thread[] threads)
|
Thread |
start(Runnable target)
Waits for a ThreadPool.PooledThread to become available and starts a
Runnable in it. |
Thread |
start(Runnable target,
long timeout)
Waits for a ThreadPool.PooledThread to become available and starts a
Runnable in it. |
Thread |
start(Runnable target,
long timeout,
String name)
Waits for a ThreadPool.PooledThread to become available and starts a
Runnable in it. |
Thread |
start(Runnable target,
String name)
Waits for a ThreadPool.PooledThread to become available and starts a
Runnable in it. |
private Thread |
start0(Runnable target,
long timeout,
String name)
|
private ThreadPool.PooledThread |
startThread(Runnable target,
String name)
|
(package private) void |
threadAvailable(ThreadPool.PooledThread thread)
|
(package private) void |
threadExiting(ThreadPool.PooledThread thread)
|
Methods inherited from class java.lang.ThreadGroup |
activeCount, activeGroupCount, add, add, allowThreadSuspension, checkAccess, destroy, enumerate, enumerate, enumerate, enumerate, enumerate, enumerate, getMaxPriority, getName, getParent, interrupt, isDaemon, isDestroyed, list, list, parentOf, remove, remove, resume, setDaemon, setMaxPriority, stop, stopOrSuspend, suspend, toString, uncaughtException |
Methods inherited from class java.lang.Object |
|
Field Detail |
private static int threadID
ThreadPool.PooledThread
names.private long timeout
ThreadPool.PooledThread
s
out of this ThreadPool
. Any negative value is
taken to indicate infinity.private long idleTimeout
ThreadPool.PooledThread
s in this
ThreadPool
should wait before aging off. Any
negative value is taken to indicate infinity.private final Collection listeners
Collection
of ThreadPoolListener
s that are
alerted when ThreadPool.PooledThread
s become available and leave this
ThreadPool
.private LinkedList pool
LinkedList
of ThreadPool.PooledThread
s that
are idling and ready to perform a job. Although this field is a
LinkedList
, it is used for its stack-like features.private int max
ThreadPool.PooledThread
s allowed. At no point
should the number of ThreadPool.PooledThread
s in the pool exceed this
number.private int active
ThreadPool.PooledThread
s in this
ThreadPool
. A ThreadPool.PooledThread
is active for
this purpose if it is either pooled and idling or running a
job.private boolean isDaemon
ThreadPool.PooledThread
s in this
ThreadPool
should be created as daemon ThreadPool.PooledThread
s.private int priority
ThreadPool.PooledThread
s in this
ThreadPool
.private boolean isClosed
ThreadPool
is closed.Constructor Detail |
public ThreadPool(String name, int max) throws IllegalArgumentException
ThreadPool
of daemon ThreadPool.PooledThread
s.name
- the name of the new ThreadPool
max
- the maximum allowed number of ThreadPool.PooledThread
sIllegalArgumentException
- if max < 0
public ThreadPool(ThreadGroup parent, String name, int max) throws IllegalArgumentException
ThreadPool
of daemon ThreadPool.PooledThread
s.parent
- the parent ThreadGroup
name
- the name of the new ThreadPool
max
- the maximum allowed number of ThreadPool.PooledThread
sIllegalArgumentException
- if max < 0
public ThreadPool(String name, int max, boolean isDaemon) throws IllegalArgumentException
ThreadPool
.name
- the name of the new ThreadPool
max
- the maximum allowed number of ThreadPool.PooledThread
sisDaemon
- if true
, all ThreadPool.PooledThread
s in this
ThreadPool
will be daemon
ThreadPool.PooledThread
s.IllegalArgumentException
- if max < 0
public ThreadPool(ThreadGroup parent, String name, int max, boolean isDaemon) throws IllegalArgumentException
ThreadPool
.parent
- the parent ThreadGroup
name
- the name of the new ThreadPool
max
- the maximum allowed number of ThreadPool.PooledThread
sisDaemon
- if true
, all ThreadPool.PooledThread
s in this
ThreadPool
will be daemon
ThreadPool.PooledThread
sIllegalArgumentException
- if max < 0
Method Detail |
private final void init(int max, boolean isDaemon) throws IllegalArgumentException
ThreadPool
so that it will permit
only the supplied number of ThreadPool.PooledThread
s to exist.max
- the maximum allowed number of ThreadPool.PooledThread
sisDaemon
- if true
, all ThreadPool.PooledThread
s in this
ThreadPool
will be daemon
ThreadPool.PooledThread
sIllegalArgumentException
- if max < 0
public void setTimeout(long timeout)
ThreadPool.PooledThread
s
from this ThreadPool
or for closing this
ThreadPool
. A negative value specifies an infinite
timeout. Calling the start(Runnable, long)
method (or
any variation that takes a timeout
argument) will
override this setting.timeout
- the new timeout valuepublic long getTimeout()
ThreadPool.PooledThread
s
from this ThreadPool
. The default value is
negative, which indicates an infinite wait.public void setIdleTimeout(long timeout)
ThreadPool.PooledThread
s to
exit. A negative value specifies that an idle thread never exits.public long getIdleTimeout()
ThreadPool.PooledThread
s to
exit. The default value is negative, which indicates that idle
ThreadPool.PooledThread
s never exit.public void addThreadPoolListener(ThreadPoolListener listener)
public void removeThreadPoolListener(ThreadPoolListener listener)
public int getPriority()
ThreadPool
. The default value is that of the thread
that created this ThreadPool
.public void setPriority(int priority) throws IllegalArgumentException
ThreadPool
.IllegalArgumentException
- if priority is out of rangepublic int getMaximumAllowed()
ThreadPool.PooledThread
s.public int getAvailableCount()
ThreadPool.PooledThread
s in this
ThreadPool
.public int getPooledCount()
ThreadPool.PooledThread
s in this
ThreadPool
that are either available or in use.public int getThreadCount()
ThreadPool.PooledThread
s in this
ThreadGroup
. Delegates internally by
default to the activeCount()
method.public Thread[] getAllThreads()
ThreadGroup
private Thread[] sort(Thread[] threads)
public Thread start(Runnable target) throws NoThreadException, InterruptedException
ThreadPool.PooledThread
to become available and starts a
Runnable
in it. If there are no available ThreadPool.PooledThread
s and the number of active ThreadPool.PooledThread
s is less than
the maximum allowed, then a newly created thread is returned.target
- the Runnable
instance that gets started by
the returned ThreadPool.PooledThread
ThreadPool.PooledThread
that has been started on the given
Runnable
.NoThreadException
- if no ThreadPool.PooledThread
could be obtained.InterruptedException
- if interrupted while waiting for a
ThreadPool.PooledThread
to become availablepublic Thread start(Runnable target, long timeout) throws NoThreadException, InterruptedException
ThreadPool.PooledThread
to become available and starts a
Runnable
in it. If there are no available ThreadPool.PooledThread
s and the number of active ThreadPool.PooledThread
s is less than
the maximum allowed, then a newly created ThreadPool.PooledThread
is returned.target
- the Runnable
instance that gets started by
the returned thread.timeout
- milliseconds to wait for a ThreadPool.PooledThread
to become
available. If zero, don't wait at all. If negative, wait forever.ThreadPool.PooledThread
that has been started on the given
Runnable
.NoThreadException
- If no ThreadPool.PooledThread
could be obtained.InterruptedException
- If interrupted while waiting for a
ThreadPool.PooledThread
to become available.public Thread start(Runnable target, String name) throws NoThreadException, InterruptedException
ThreadPool.PooledThread
to become available and starts a
Runnable
in it. If there are no available ThreadPool.PooledThread
s and the number of active ThreadPool.PooledThread
s is less than
the maximum allowed, then a newly created ThreadPool.PooledThread
is returned.target
- the Runnable
instance that gets started by
the returned ThreadPool.PooledThread
name
- the name to give the ThreadPool.PooledThread
ThreadPool.PooledThread
that has been started on the given
Runnable
.NoThreadException
- if no ThreadPool.PooledThread
could be obtained.InterruptedException
- if interrupted while waiting for a
ThreadPool.PooledThread
to become available.public Thread start(Runnable target, long timeout, String name) throws NoThreadException, InterruptedException
ThreadPool.PooledThread
to become available and starts a
Runnable
in it. If there are no available ThreadPool.PooledThread
s and the number of active ThreadPool.PooledThread
s is less than
the maximum allowed, then a newly created ThreadPool.PooledThread
is
returned.target
- the Runnable
instance that gets started by
the returned ThreadPool.PooledThread
timeout
- milliseconds to wait for a ThreadPool.PooledThread
to become
available. If zero, don't wait at all. If negative, wait forever.name
- the name to give the ThreadPool.PooledThread
ThreadPool.PooledThread
that has been started on the given
Runnable
.NoThreadException
- if no ThreadPool.PooledThread
could be obtainedInterruptedException
- if interrupted while waiting for a
ThreadPool.PooledThread
to become available.private Thread start0(Runnable target, long timeout, String name) throws NoThreadException, InterruptedException
public boolean isClosed()
public void close() throws InterruptedException
ThreadPool.PooledThread
s in this
ThreadPool
as they become available. This method may
block forever if any ThreadPool.PooledThread
s are never returned to this
ThreadPool
.public void close(long timeout) throws InterruptedException
ThreadPool.PooledThread
s in this
ThreadPool
as they become available. If all the
ThreadPool.PooledThread
s cannot become available within the specified
timeout, any active ThreadPool.PooledThread
s not yet returned to this
ThreadPool
are interrupted.timeout
- milliseconds to wait before unavailable ThreadPool.PooledThread
s
are interrupted. If zero, don't wait at all. If negative, wait forever.private ThreadPool.PooledThread startThread(Runnable target, String name)
private void ensureOpen() throws ThreadPoolClosedException
void threadAvailable(ThreadPool.PooledThread thread)
void threadExiting(ThreadPool.PooledThread thread)
|
foundry-0.9.1 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |