|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.snmp4j.util.ThreadPool
public class ThreadPool
The ThreadPool
provides a pool of a fixed number of threads
that are capable to execute tasks that implement the Runnable
interface concurrently. The ThreadPool blocks when all threads are busy
with tasks and an additional task is added.
Field Summary | |
---|---|
protected java.lang.String |
name
|
protected boolean |
respawnThreads
|
protected boolean |
stop
|
protected java.util.Vector |
taskManagers
|
Constructor Summary | |
---|---|
protected |
ThreadPool()
|
Method Summary | |
---|---|
void |
cancel()
Cancels all threads non-blocking by interrupting them. |
static ThreadPool |
create(java.lang.String name,
int size)
Creates a thread pool with the supplied name and size. |
void |
execute(WorkerTask task)
Executes a task on behalf of this thread pool. |
java.lang.String |
getName()
Returns the name of the thread pool. |
protected java.lang.String |
getTaskManagerName(java.lang.String prefix,
int index)
|
void |
interrupt()
Interrupts all threads in the pool. |
boolean |
isIdle()
Checks if all threads of the pool are idle. |
boolean |
isRespawnThreads()
Tests if the threads are respawn (recreates) when they have been stopped or canceled. |
void |
setRespawnThreads(boolean respawnThreads)
Specifies whether threads are respawned by this thread pool after they have been stopped or not. |
protected void |
setup(java.lang.String name,
int size)
|
void |
stop()
Stops all threads in this thread pool gracefully. |
boolean |
tryToExecute(WorkerTask task)
Tries to execute a task on behalf of this thread pool. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected java.util.Vector taskManagers
protected java.lang.String name
protected volatile boolean stop
protected boolean respawnThreads
Constructor Detail |
---|
protected ThreadPool()
Method Detail |
---|
protected java.lang.String getTaskManagerName(java.lang.String prefix, int index)
protected void setup(java.lang.String name, int size)
public static ThreadPool create(java.lang.String name, int size)
name
- the name prefix for the threads in this pool.size
- the number of threads in this pool. This number also specifies the
number of concurrent tasks that can be executed with this pool.
ThreadPool
instance.public void execute(WorkerTask task)
execute
in interface WorkerPool
task
- a Runnable
to execute.public boolean tryToExecute(WorkerTask task)
false
. Otherwise the task
is executed in background.
tryToExecute
in interface WorkerPool
task
- a Runnable
to execute.
true
if the task is executing.public boolean isRespawnThreads()
true
if threads are respawn.public void setRespawnThreads(boolean respawnThreads)
respawnThreads
- if true
then threads will be respawn.public java.lang.String getName()
public void stop()
stop
in interface WorkerPool
public void cancel()
cancel
in interface WorkerPool
public void interrupt()
public boolean isIdle()
isIdle
in interface WorkerPool
true
if all threads are idle.
|
Copyright 2005-2010 Frank Fock (SNMP4J.org) | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |