Modifier and Type | Class and Description |
---|---|
static interface |
RunnableConsumerThreadPool.RunnableCompletionListener
This interface is used to define a listener for the thread pool that is
notified when an enqueued runnable completes.
|
static interface |
RunnableConsumerThreadPool.RunnableErrorListener
This interface is used to define a listerer for the thread pool that is
notified if an error occurs processing a runnable.
|
RUNNING, START_PENDING, STARTING, STATUS_NAMES, STOP_PENDING, STOPPED
Constructor and Description |
---|
RunnableConsumerThreadPool(String name,
float loMark,
float hiMark,
int max)
Constructs a new instance of the thread pool class.
|
Modifier and Type | Method and Description |
---|---|
void |
addCompletionListener(RunnableConsumerThreadPool.RunnableCompletionListener listener)
Adds a listener that is notified upon completion of each runnable.
|
void |
addErrorListener(RunnableConsumerThreadPool.RunnableErrorListener listener)
Adds a listener that is notified of error from any runnable.
|
String |
getName()
Returns the name of the thread pool.
|
FifoQueue<Runnable> |
getRunQueue()
Returns the input queue where
Runnable objects
are enqueued. |
int |
getStatus()
Returns the current status of the fiber.
|
void |
removeCompletionListener(RunnableConsumerThreadPool.RunnableCompletionListener listener)
Removes a previous register listener.
|
void |
removeErrorListener(RunnableConsumerThreadPool.RunnableErrorListener listener)
Removes a previous register listener.
|
void |
start()
Starts the thread pool.
|
void |
stop()
Begins the shutdown process of the thread pool.
|
public RunnableConsumerThreadPool(String name, float loMark, float hiMark, int max)
Constructs a new instance of the thread pool class. The thread pool
consumes Runnable
instances from the input
queue, calling the run
method as they are consumed.
The size of the thread pool is controlled by the low and high water marks, each water mark being the ratio of queue elements to threads. As the ratio grows past the high water mark more threads are added, up to the maximum amount. As the ratio drops past the low water mark the number of threads are reduced.
name
- The name of the thread pool.loMark
- The lower ratio used to mark thread reduction.hiMark
- The high ration used to mark thread production.max
- The maximum number of threads in the pool.IllegalArgumentException
- Thrown if the low or high marks are invalid, or the
maximum number of threads is invalid.public FifoQueue<Runnable> getRunQueue()
Runnable
objects
are enqueued. Each runnable object will be executed in the order that it
is entered.public void start()
public void stop()
public int getStatus()
public String getName()
public void addCompletionListener(RunnableConsumerThreadPool.RunnableCompletionListener listener)
listener
- The listener notified on runnable completion.public void removeCompletionListener(RunnableConsumerThreadPool.RunnableCompletionListener listener)
listener
- The listener to remove from notification.public void addErrorListener(RunnableConsumerThreadPool.RunnableErrorListener listener)
listener
- The listener notified on runnable completion.public void removeErrorListener(RunnableConsumerThreadPool.RunnableErrorListener listener)
listener
- The listener to remove from notification.Copyright © 2015. All Rights Reserved.