#include <ThreadPool.h>
Inheritance diagram for activemq::concurrent::ThreadPool:
Public Types | |
typedef std::pair< Runnable *, TaskListener * > | Task |
Public Member Functions | |
ThreadPool (void) | |
virtual | ~ThreadPool (void) |
virtual void | queueTask (Task task) throw ( exceptions::ActiveMQException ) |
virtual Task | deQueueTask (void) throw ( exceptions::ActiveMQException ) |
virtual unsigned long | getPoolSize (void) const |
virtual unsigned long | getBacklog (void) const |
virtual void | reserve (unsigned long size) |
virtual unsigned long | getMaxThreads (void) const |
virtual void | setMaxThreads (unsigned long maxThreads) |
virtual unsigned long | getBlockSize (void) const |
virtual void | setBlockSize (unsigned long blockSize) |
virtual unsigned long | getFreeThreadCount (void) const |
virtual void | onTaskStarted (PooledThread *thread) |
virtual void | onTaskCompleted (PooledThread *thread) |
virtual void | onTaskException (PooledThread *thread, exceptions::ActiveMQException &ex) |
Static Public Member Functions | |
static ThreadPool * | getInstance (void) |
Static Public Attributes | |
static const size_t | DEFAULT_MAX_POOL_SIZE = 10 |
static const size_t | DEFAULT_MAX_BLOCK_SIZE = 3 |
Private Member Functions | |
LOGCMS_DECLARE (logger) | |
LOGCMS_DECLARE (marker) | |
void | AllocateThreads (unsigned long count) |
Private Attributes | |
std::vector< PooledThread * > | pool |
util::Queue< Task > | queue |
unsigned long | maxThreads |
unsigned long | blockSize |
bool | shutdown |
unsigned long | freeThreads |
Mutex | poolLock |
Static Private Attributes | |
static ThreadPool | instance |
When the user queues a task they must also queue a listner to be notified when the task has completed, this provides the user with a mechanism to know when a task object can be freed.
To have the Thread Pool perform a task, the user enqueue's an object that implements the Runnable
insterface and one of the worker threads will executing it in its thread context.
|
|
|
|
|
|
|
Allocates the requested ammount of Threads, won't exceed
|
|
DeQueue a task to be completed by one of the Pooled Threads. A caller of this method will block until there is something in the tasks queue, therefore care must be taken when calling this function. Normally clients of ThreadPool don't use this, only the
|
|
Returns the current backlog of items in the tasks queue, this is how much work is still waiting to get done.
|
|
Gets the Max number of threads that can be allocated at a time when new threads are needed.
|
|
Returns the current number of available threads in the pool, threads that are performing a user task are considered unavailable. This value could change immeadiately after calling as Threads could finish right after and be available again. This is informational only.
|
|
Return the one and only Thread Pool instance.
|
|
Get the Max Number of Threads this Pool can contain
|
|
Returns the current number of Threads in the Pool, this is how many there are now, not how many are active or the max number that might exist.
|
|
|
|
|
|
Called by a pooled thread when it has completed a task and is going back to waiting for another task to run, this will increment the free threads counter.
Implements activemq::concurrent::PooledThreadListener. |
|
Called by a pooled thread when it has encountered an exception while running a user task, after receiving this notification the callee should assume that the PooledThread is now no longer running.
Implements activemq::concurrent::PooledThreadListener. |
|
Called by a pooled thread when it is about to begin executing a new task. This will decrement the available threads counter so that this object knows when there are no more free threads and must create new ones.
Implements activemq::concurrent::PooledThreadListener. |
|
Queue a task to be completed by one of the Pooled Threads. tasks are serviced as soon as a
|
|
Ensures that there is at least the specified number of Threads allocated to the pool. If the size is greater than the MAX number of threads in the pool, then only MAX threads are reservved. If the size is smaller than the number of threads currently in the pool, than nothing is done.
|
|
Sets the Max number of Threads that can be allocated at a time when the Thread Pool determines that more Threads are needed.
|
|
Sets the Max number of threads this pool can contian. if this value is smaller than the current size of the pool nothing is done.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|