activemq-cpp-3.6.0
|
Defines a Thread Pool object that implements the functionality of pooling threads to perform user tasks. More...
#include <src/main/decaf/util/concurrent/ThreadPoolExecutor.h>
Data Structures | |
class | AbortPolicy |
Handler policy for tasks that are rejected upon a call to ThreadPoolExecutor::execute this class always throws a RejectedExecutionException. More... | |
class | CallerRunsPolicy |
Handler policy for tasks that are rejected upon a call to ThreadPoolExecutor::execute this class will attempt to run the task in the Thread that called the execute method unless the executor is shutdown in which case the task is not run and is destroyed. More... | |
class | DiscardOldestPolicy |
Handler policy for tasks that are rejected upon a call to ThreadPoolExecutor::execute this class always destroys the oldest unexecuted task in the Queue and then attempts to execute the rejected task using the passed in executor. More... | |
class | DiscardPolicy |
Handler policy for tasks that are rejected upon a call to ThreadPoolExecutor::execute this class always destroys the rejected task and returns quietly. More... |
Public Member Functions | |
ThreadPoolExecutor (int corePoolSize, int maxPoolSize, long long keepAliveTime, const TimeUnit &unit, BlockingQueue< decaf::lang::Runnable * > *workQueue) | |
Creates a new instance of a ThreadPoolExecutor. | |
ThreadPoolExecutor (int corePoolSize, int maxPoolSize, long long keepAliveTime, const TimeUnit &unit, BlockingQueue< decaf::lang::Runnable * > *workQueue, RejectedExecutionHandler *handler) | |
Creates a new instance of a ThreadPoolExecutor. | |
ThreadPoolExecutor (int corePoolSize, int maxPoolSize, long long keepAliveTime, const TimeUnit &unit, BlockingQueue< decaf::lang::Runnable * > *workQueue, ThreadFactory *threadFactory) | |
Creates a new instance of a ThreadPoolExecutor. | |
ThreadPoolExecutor (int corePoolSize, int maxPoolSize, long long keepAliveTime, const TimeUnit &unit, BlockingQueue< decaf::lang::Runnable * > *workQueue, ThreadFactory *threadFactory, RejectedExecutionHandler *handler) | |
Creates a new instance of a ThreadPoolExecutor. | |
virtual | ~ThreadPoolExecutor () |
virtual void | execute (decaf::lang::Runnable *task) |
This method is the same as calling the two param execute method and passing true as the second argument. | |
virtual void | execute (decaf::lang::Runnable *task, bool takeOwnership) |
Executes the given command at some time in the future. | |
virtual void | shutdown () |
Performs an orderly shutdown of this Executor. | |
virtual ArrayList < decaf::lang::Runnable * > | shutdownNow () |
Attempts to stop all currently executing tasks and returns an ArrayList containing the Runnables that did not get executed, these object become the property of the caller and are not deleted by this class, they are removed from the work queue and forgotten about. | |
virtual bool | awaitTermination (long long timeout, const decaf::util::concurrent::TimeUnit &unit) |
The caller will block until the executor has completed termination meaning all tasks that where scheduled before shutdown have now completed and the executor is ready for deletion. | |
virtual bool | isShutdown () const |
Returns whether this executor has been shutdown or not. | |
virtual bool | isTerminated () const |
Returns whether all tasks have completed after this executor was shut down. | |
virtual int | getPoolSize () const |
Returns the number of threads that currently exists for this Executor. | |
virtual int | getCorePoolSize () const |
Returns the configured number of core threads for this Executor. | |
virtual void | setCorePoolSize (int poolSize) |
Set the number of threads that this executor treats as its core threads, this value will override the value set in the constructor. | |
virtual int | getMaximumPoolSize () const |
Returns the configured maximum number of threads for this Executor. | |
virtual void | setMaximumPoolSize (int maxSize) |
Sets the maximum number of workers this Executor is allowed to have at any given time above the core pool size. | |
virtual long long | getTaskCount () const |
Returns the current number of pending tasks in the work queue. | |
virtual int | getActiveCount () const |
Returns an approximation of the number of threads that are currently running tasks for this executor. | |
virtual long long | getCompletedTaskCount () const |
Returns the approximate number of Tasks that have been completed by this Executor, this value never decreases. | |
virtual int | getLargestPoolSize () const |
Returns the most Threads that have ever been active at one time within this Executors Thread pool. | |
virtual BlockingQueue < decaf::lang::Runnable * > * | getQueue () |
Provides access to the Task Queue used by this Executor. | |
virtual bool | isTerminating () const |
Returns true if the executor has begin the process of terminating but has not yet completed the process of shutting down all worker threads. | |
virtual void | allowCoreThreadTimeout (bool value) |
When true this setting allows the threads in the core pool to terminate if they sit idle longer than the set keep alive time. | |
virtual bool | allowsCoreThreadTimeout () const |
Returns whether this executor has been configured to allow core threads to terminate if they sit idle longer than the configured keep alive time. | |
virtual long long | getKeepAliveTime (const TimeUnit &unit) const |
Returns the currently set value for the maximum amount of time a worker Thread that is not part of the core threads is allowed to sit idle before it terminates. | |
virtual void | setKeepAliveTime (long long timeout, const TimeUnit &unit) |
Configures the amount of time a non core Thread will remain alive after it has completed its assigned task. | |
virtual void | setThreadFactory (ThreadFactory *factory) |
Sets the ThreadFactory instance used to create new Threads for this Executor. | |
virtual ThreadFactory * | getThreadFactory () const |
Gets the currently configured ThreadFactory. | |
virtual RejectedExecutionHandler * | getRejectedExecutionHandler () const |
Gets the currently configured RejectedExecutionHandler for this Executor. | |
virtual void | setRejectedExecutionHandler (RejectedExecutionHandler *handler) |
Sets the new RejectedExecutionHandler that this executor should use to process any rejected Runnable tasks. | |
virtual bool | prestartCoreThread () |
By default a Core thread is only created once the first task is queued, this method forces the creation of core thread that waits in an idle mode for new work to be enqueued. | |
virtual int | prestartAllCoreThreads () |
This method will create and start new core threads running in an idle state waiting for new tasks up to the set core thread limit. | |
bool | remove (decaf::lang::Runnable *task) |
Attempts to remove the Runnable from the work queue, if successful then the caller now owns the Runnable and is responsible for deleting it. | |
virtual void | purge () |
Attempts to remove any Future derived tasks from the pending work queue if they have been canceled. | |
Public Member Functions inherited from decaf::util::concurrent::AbstractExecutorService | |
AbstractExecutorService () | |
virtual | ~AbstractExecutorService () |
Public Member Functions inherited from decaf::util::concurrent::ExecutorService | |
virtual | ~ExecutorService () |
template<typename E > | |
Future< E > * | submit (Callable< E > *task, bool takeOwnership=true) |
Submits a value-returning task for execution and returns a Future pointer representing the pending results of the task. | |
template<typename E > | |
Future< E > * | submit (decaf::lang::Runnable *task, const E &result, bool takeOwnership=true) |
Submits a Runnable task for execution and returns a Future representing that task. | |
template<typename E > | |
Future< E > * | submit (decaf::lang::Runnable *task, bool takeOwnership=true) |
Submits a Runnable object for execution. | |
Public Member Functions inherited from decaf::util::concurrent::Executor | |
virtual | ~Executor () |
Protected Member Functions | |
virtual void | beforeExecute (decaf::lang::Thread *thread, decaf::lang::Runnable *task) |
Method called before a task is executed by the given thread. | |
virtual void | afterExecute (decaf::lang::Runnable *task, decaf::lang::Throwable *error) |
Called upon completion of execution of a given task. | |
virtual void | terminated () |
Method invoked when the Executor has terminated, by default this method does nothing. | |
virtual void | onShutdown () |
Used by some Decaf ThreadPoolExecutor extensions to correctly handle the shutdown case. | |
Protected Member Functions inherited from decaf::util::concurrent::AbstractExecutorService | |
virtual void | doSubmit (FutureType *future) |
Perform the actual submit of a FutureType instance, the caller is responsible for creating the properly typed Future<E> object and returning that to its caller. |
Friends | |
class | ExecutorKernel |
Defines a Thread Pool object that implements the functionality of pooling threads to perform user tasks.
The Thread Poll has max size that it will grow to. The thread pool allocates threads in blocks. When there are no waiting worker threads and a task is queued then a new batch is allocated. The user can specify the size of the blocks, otherwise a default value is used.
When the user queues a task they must also queue a listener 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
interface and one of the worker threads will executing it in its thread context.
decaf::util::concurrent::ThreadPoolExecutor::ThreadPoolExecutor | ( | int | corePoolSize, |
int | maxPoolSize, | ||
long long | keepAliveTime, | ||
const TimeUnit & | unit, | ||
BlockingQueue< decaf::lang::Runnable * > * | workQueue | ||
) |
Creates a new instance of a ThreadPoolExecutor.
The executor instance is configured with the passed in parameters and a default thread Factory is used along with a default rejected execution handler.
corePoolSize | The number of threads to pool regardless of their idle state. |
maxPoolSize | The maximum number of threads that will ever exist at one time in the pool. |
keepAliveTime | The maximum time to keep a thread in the pool for if the number of current threads exceeds to core pool size. |
unit | The units that the keepAliveTime is specified in. |
workQueue | A BlockingQueue implementation that will be used to hold Runnable tasks that are awaiting execution within this executor. The Executor takes ownership of the BlockingQueue instance passed once this method returns. |
IllegalArguementException | if the corePoolSize or keepAliveTime are negative or the or if maximumPoolSize is less than or equal to zero, or if corePoolSize is greater than maximumPoolSize. |
NullPointerException | if the workQueue pointer is NULL. |
decaf::util::concurrent::ThreadPoolExecutor::ThreadPoolExecutor | ( | int | corePoolSize, |
int | maxPoolSize, | ||
long long | keepAliveTime, | ||
const TimeUnit & | unit, | ||
BlockingQueue< decaf::lang::Runnable * > * | workQueue, | ||
RejectedExecutionHandler * | handler | ||
) |
Creates a new instance of a ThreadPoolExecutor.
The executor instance is configured with the passed in parameters and a default thread Factory is used along with a default rejected execution handler.
corePoolSize | The number of threads to pool regardless of their idle state. |
maxPoolSize | The maximum number of threads that will ever exist at one time in the pool. |
keepAliveTime | The maximum time to keep a thread in the pool for if the number of current threads exceeds to core pool size. |
unit | The units that the keepAliveTime is specified in. |
workQueue | A BlockingQueue implementation that will be used to hold Runnable tasks that are awaiting execution within this executor. The Executor takes ownership of the BlockingQueue instance passed once this method returns. |
handler | A RejectedExecutionHandler implementation that will be used to handle any rejected tasks when they are submitted to this executor. The Executor takes ownership of the RejectedExecutionHandler instance passed once this method returns. |
IllegalArguementException | if the corePoolSize or keepAliveTime are negative or the or if maximumPoolSize is less than or equal to zero, or if corePoolSize is greater than maximumPoolSize. |
NullPointerException | if the workQueue pointer is NULL. |
decaf::util::concurrent::ThreadPoolExecutor::ThreadPoolExecutor | ( | int | corePoolSize, |
int | maxPoolSize, | ||
long long | keepAliveTime, | ||
const TimeUnit & | unit, | ||
BlockingQueue< decaf::lang::Runnable * > * | workQueue, | ||
ThreadFactory * | threadFactory | ||
) |
Creates a new instance of a ThreadPoolExecutor.
The executor instance is configured with the passed in parameters and a default thread Factory is used along with a default rejected execution handler.
corePoolSize | The number of threads to pool regardless of their idle state. |
maxPoolSize | The maximum number of threads that will ever exist at one time in the pool. |
keepAliveTime | The maximum time to keep a thread in the pool for if the number of current threads exceeds to core pool size. |
unit | The units that the keepAliveTime is specified in. |
workQueue | A BlockingQueue implementation that will be used to hold Runnable tasks that are awaiting execution within this executor. The Executor takes ownership of the BlockingQueue instance passed once this method returns. |
threadFactory | A ThreadFactory implementation that will be used to create worker threads that are used by this executor to run the submitted tasks. The Executor takes ownership of the ThreadFactory instance passed once this method returns. |
IllegalArguementException | if the corePoolSize or keepAliveTime are negative or the or if maximumPoolSize is less than or equal to zero, or if corePoolSize is greater than maximumPoolSize. |
NullPointerException | if the workQueue pointer is NULL. |
decaf::util::concurrent::ThreadPoolExecutor::ThreadPoolExecutor | ( | int | corePoolSize, |
int | maxPoolSize, | ||
long long | keepAliveTime, | ||
const TimeUnit & | unit, | ||
BlockingQueue< decaf::lang::Runnable * > * | workQueue, | ||
ThreadFactory * | threadFactory, | ||
RejectedExecutionHandler * | handler | ||
) |
Creates a new instance of a ThreadPoolExecutor.
The executor instance is configured with the passed in parameters and a default thread Factory is used along with a default rejected execution handler.
corePoolSize | The number of threads to pool regardless of their idle state. |
maxPoolSize | The maximum number of threads that will ever exist at one time in the pool. |
keepAliveTime | The maximum time to keep a thread in the pool for if the number of current threads exceeds to core pool size. |
unit | The units that the keepAliveTime is specified in. |
workQueue | A BlockingQueue implementation that will be used to hold Runnable tasks that are awaiting execution within this executor. The Executor takes ownership of the BlockingQueue instance passed once this method returns. |
threadFactory | A ThreadFactory implementation that will be used to create worker threads that are used by this executor to run the submitted tasks. The Executor takes ownership of the ThreadFactory instance passed once this method returns. |
handler | A RejectedExecutionHandler implementation that will be used to handle any rejected tasks when they are submitted to this executor. The Executor takes ownership of the BlockingQueue instance passed once this method returns. |
IllegalArguementException | if the corePoolSize or keepAliveTime are negative or the or if maximumPoolSize is less than or equal to zero, or if corePoolSize is greater than maximumPoolSize. |
NullPointerException | if the workQueue pointer is NULL. |
|
virtual |
|
protectedvirtual |
Called upon completion of execution of a given task.
This method is called from the Thread that executed the given Runnable. If the Throwable pointer is not NULL then its value is the Exception that caused the task to terminate.
The base class implementation does nothing, a derived class should call this method on its base class to ensure that all subclasses have a chance to process the afterExecute event.
task | The Runnable instance that was executed by the calling Thread. |
error | The exception that was thrown from the given Runnable. |
|
virtual |
When true this setting allows the threads in the core pool to terminate if they sit idle longer than the set keep alive time.
Core threads that terminate are replaced as needed by new ones on demand. This settings requires that the set keep alive time be greater than zero and will throw an IllegalArguementException if that is not the case.
value | Boolean value indicating if core threads are allowed to time out when idle. |
IllegalArgumentException | if the keep alive time is set to zero. |
|
virtual |
Returns whether this executor has been configured to allow core threads to terminate if they sit idle longer than the configured keep alive time.
Threads that are not core threads continue to time out using the set keep alive value regardless of whether this option is enabled.
|
virtual |
The caller will block until the executor has completed termination meaning all tasks that where scheduled before shutdown have now completed and the executor is ready for deletion.
If the timeout period elapses before the executor reaches the terminated state then this method return false to indicate it has not terminated.
timeout | The amount of time to wait before abandoning the wait for termination. |
unit | The unit of time that the timeout value represents. |
InterruptedException | if this call is interrupted while awaiting termination. |
Implements decaf::util::concurrent::ExecutorService.
|
protectedvirtual |
Method called before a task is executed by the given thread.
The default implementation of this method does nothing, however a subclass can override this method to add some new functionality.
It is recommended that a subclass call this method on its base class to ensure that all base classes have a chance to process this event.
thread | The thread that will be executing the given task. |
task | The task that will be executed by the given thread. |
|
virtual |
This method is the same as calling the two param execute method and passing true as the second argument.
command | The runnable task to be executed. |
RejectedExecutionException | if this task cannot be accepted for execution. |
NullPointerException | if command is null |
Implements decaf::util::concurrent::Executor.
Referenced by decaf::util::concurrent::ThreadPoolExecutor::DiscardOldestPolicy::rejectedExecution().
|
virtual |
Executes the given command at some time in the future.
The command may execute in a new thread, in a pooled thread, or in the calling thread, at the discretion of the Executor
implementation.
command | The runnable task to be executed. |
takeOwnership | Indicates if the Executor should assume ownership of the task and delete the pointer once the task has completed. |
RejectedExecutionException | if this task cannot be accepted for execution. |
NullPointerException | if command is null |
Implements decaf::util::concurrent::Executor.
|
virtual |
Returns an approximation of the number of threads that are currently running tasks for this executor.
This value can change rapidly.
|
virtual |
|
virtual |
Returns the configured number of core threads for this Executor.
|
virtual |
Returns the currently set value for the maximum amount of time a worker Thread that is not part of the core threads is allowed to sit idle before it terminates.
unit | The unit of time to return the results in. |
|
virtual |
Returns the most Threads that have ever been active at one time within this Executors Thread pool.
|
virtual |
Returns the configured maximum number of threads for this Executor.
|
virtual |
Returns the number of threads that currently exists for this Executor.
|
virtual |
Provides access to the Task Queue used by this Executor.
This method is meant mainly for debugging and monitoring, care should be taken when using this method. The executor continues to execute tasks from the Queue.
Referenced by decaf::util::concurrent::ThreadPoolExecutor::DiscardOldestPolicy::rejectedExecution().
|
virtual |
Gets the currently configured RejectedExecutionHandler for this Executor.
|
virtual |
Returns the current number of pending tasks in the work queue.
This is an approximation as the number of pending tasks can quickly changes as tasks complete and new tasks are started.
|
virtual |
Gets the currently configured ThreadFactory.
It is considered a programming error to delete the pointer returned by this method.
|
virtual |
Returns whether this executor has been shutdown or not.
Implements decaf::util::concurrent::ExecutorService.
Referenced by decaf::util::concurrent::ThreadPoolExecutor::DiscardOldestPolicy::rejectedExecution().
|
virtual |
Returns whether all tasks have completed after this executor was shut down.
Implements decaf::util::concurrent::ExecutorService.
|
virtual |
Returns true if the executor has begin the process of terminating but has not yet completed the process of shutting down all worker threads.
If the Executor does not transition from this state to terminated after some time its generally an indication that one of the submitted tasks will not complete and the executor is locked in a terminating state.
|
protectedvirtual |
Used by some Decaf ThreadPoolExecutor extensions to correctly handle the shutdown case.
|
virtual |
This method will create and start new core threads running in an idle state waiting for new tasks up to the set core thread limit.
When the limit is reached this method returns zero to indicate no more core threads can be created.
|
virtual |
By default a Core thread is only created once the first task is queued, this method forces the creation of core thread that waits in an idle mode for new work to be enqueued.
If the limit on core threads has already been reached then this method returns false.
|
virtual |
Attempts to remove any Future derived tasks from the pending work queue if they have been canceled.
This method can be used to more quickly remove and reclaim space as canceled tasks are not run but must await a worker thread to be removed normally. Since there are multiple threads in operation its possible for this method to not remove all canceled tasks from the work queue.
bool decaf::util::concurrent::ThreadPoolExecutor::remove | ( | decaf::lang::Runnable * | task | ) |
Attempts to remove the Runnable from the work queue, if successful then the caller now owns the Runnable and is responsible for deleting it.
task | The task that is to be removed from the work queue. |
|
virtual |
Set the number of threads that this executor treats as its core threads, this value will override the value set in the constructor.
If the value given is less than the current value then the core threads will shrink to the new value over time. If the value is larger than the current value then new threads may be started to process currently pending tasks, otherwise they will be started as needed when new tasks arrive.
poolSize | The new core pool size for this executor. |
IllegalArgumentException | if the pool size value is less than zero. |
|
virtual |
Configures the amount of time a non core Thread will remain alive after it has completed its assigned task.
This value can also be applied to core threads if the allowCoreThreadsTimeout option is enabled.
timeout | The amount of time an idle worker will live before terminating. |
unit | The units that the timeout is given in. |
IllegalArgumentException | if allowCoreThreadsTimeout is enabled and the the timeout value given is zero, or the timeout given is negative. |
|
virtual |
Sets the maximum number of workers this Executor is allowed to have at any given time above the core pool size.
This new value overrides any set in the constructor and if smaller than the current value worker threads will terminate as they complete their current tasks and become idle.
maxSize | The new maximum allowed worker pool size. |
IllegalArgumentException | if maxSize is negative or less than core pool size. |
|
virtual |
Sets the new RejectedExecutionHandler that this executor should use to process any rejected Runnable tasks.
This executor takes ownership of the supplied pointer and will desotroy it upon termination, any previous handler is destroyed by this call.
handler | The new RejectedExecutionHandler instance to use. |
NullPointerException | if the handler is NULL. |
|
virtual |
Sets the ThreadFactory instance used to create new Threads for this Executor.
This class takes ownership of the given ThreadFactory and will destroy it upon termination or when a new ThreadFactory is set using this method.
factory | A ThreadFactory instance used by this Executor to create new Threads. |
NullPointerException | if the given factory pointer is NULL. |
|
virtual |
Performs an orderly shutdown of this Executor.
Previously queued tasks are allowed to complete but no new tasks are accepted for execution. Calling this method more than once has no affect on this executor.
Implements decaf::util::concurrent::ExecutorService.
|
virtual |
Attempts to stop all currently executing tasks and returns an ArrayList containing the Runnables that did not get executed, these object become the property of the caller and are not deleted by this class, they are removed from the work queue and forgotten about.
There is no guarantee that this method will halt execution of currently executing tasks.
Implements decaf::util::concurrent::ExecutorService.
|
protectedvirtual |
Method invoked when the Executor has terminated, by default this method does nothing.
When overridden the subclass should call superclass::terminated to ensure that all subclasses have their terminated method invoked.
|
friend |