activemq-cpp-3.6.0
decaf::util::concurrent::Executors Class Reference

Implements a set of utilities for use with Executors, ExecutorService, ThreadFactory, and Callable types, as well as providing factory methods for instance of these types configured for the most common use cases. More...

#include <src/main/decaf/util/concurrent/Executors.h>

Data Structures

class  RunnableAdapter
 A Callable subclass that runs given task and returns given result.

Public Member Functions

virtual ~Executors ()

Static Public Member Functions

static ThreadFactorygetDefaultThreadFactory ()
 Creates and returns a new ThreadFactory that expresses the default behavior for ThreadFactories used in Executor classes.
static ExecutorServicenewFixedThreadPool (int nThreads)
 Creates a new ThreadPoolExecutor with a fixed number of threads to process incoming tasks.
static ExecutorServicenewFixedThreadPool (int nThreads, ThreadFactory *threadFactory)
 Creates a new ThreadPoolExecutor with a fixed number of threads to process incoming tasks.
static ExecutorServicenewSingleThreadExecutor ()
 Creates an Executor that uses a single worker thread operating off an unbounded queue owned by the executor.
static ExecutorServicenewSingleThreadExecutor (ThreadFactory *threadFactory)
 Creates an Executor that uses a single worker thread operating off an unbounded queue owned by the executor.
static ExecutorServiceunconfigurableExecutorService (ExecutorService *executor)
 Returns a new ExecutorService derived instance that wraps and takes ownership of the given ExecutorService pointer.
template<typename E >
static Callable< E > * callable (decaf::lang::Runnable *task, bool owns=true)
 Returns a Callable object that, when called, runs the given task and returns the default value of the template type E (or E()).
template<typename E >
static Callable< E > * callable (decaf::lang::Runnable *task, const E &result, bool owns=true)
 Returns a Callable object that, when called, runs the given task and returns the default value of the template type E (or E()).

Friends

class decaf::internal::util::concurrent::Threading

Detailed Description

Implements a set of utilities for use with Executors, ExecutorService, ThreadFactory, and Callable types, as well as providing factory methods for instance of these types configured for the most common use cases.

Since
1.0

Constructor & Destructor Documentation

virtual decaf::util::concurrent::Executors::~Executors ( )
virtual

Member Function Documentation

template<typename E >
static Callable<E>* decaf::util::concurrent::Executors::callable ( decaf::lang::Runnable task,
bool  owns = true 
)
inlinestatic

Returns a Callable object that, when called, runs the given task and returns the default value of the template type E (or E()).

Parameters
taskThe Runnable task that is to be executed.
ownsDoes the callable instance own the given Runnable task pointer, default is true.
Returns
a new Callable<E> pointer that is owned by the caller.
Exceptions
NullPointerExceptionif the Runnable task is NULL

References NULL.

template<typename E >
static Callable<E>* decaf::util::concurrent::Executors::callable ( decaf::lang::Runnable task,
const E &  result,
bool  owns = true 
)
inlinestatic

Returns a Callable object that, when called, runs the given task and returns the default value of the template type E (or E()).

Parameters
taskThe Runnable task that is to be executed.
resultThe value that is returned from the callable upon completion.
ownsDoes the callable instance own the given Runnable task pointer, default is true.
Returns
a new Callable<E> pointer that is owned by the caller.
Exceptions
NullPointerExceptionif the Runnable task is NULL

References NULL.

static ThreadFactory* decaf::util::concurrent::Executors::getDefaultThreadFactory ( )
static

Creates and returns a new ThreadFactory that expresses the default behavior for ThreadFactories used in Executor classes.

The default factory create a new non-daemon thread with normal priority and a name whose value is equal to pool-N-thread-M, where N is the sequence number of this factory, and M is the sequence number of the thread created by this factory.

Returns
a new instance of the default thread factory used in Executors, the caller takes ownership of the returned pointer.
static ExecutorService* decaf::util::concurrent::Executors::newFixedThreadPool ( int  nThreads)
static

Creates a new ThreadPoolExecutor with a fixed number of threads to process incoming tasks.

The thread pool will use an unbounded queue to store pending tasks. At any given time the maximum threads in the pool will be equal to the number given to this factory method. If a thread in the pool dies a new one will be spawned to take its place in the pool. Tasks that are submitted when all pooled threads are busy will be held until a thread is freed if the pool has allocated its assigned number of threads already.

Parameters
nThreadsThe number of threads to assign as the max for the new ExecutorService.
Returns
pointer to a new ExecutorService that is owned by the caller.
Exceptions
IllegalArgumentExceptionif nThreads is less than or equal to zero.
static ExecutorService* decaf::util::concurrent::Executors::newFixedThreadPool ( int  nThreads,
ThreadFactory threadFactory 
)
static

Creates a new ThreadPoolExecutor with a fixed number of threads to process incoming tasks.

The thread pool will use an unbounded queue to store pending tasks. At any given time the maximum threads in the pool will be equal to the number given to this factory method. If a thread in the pool dies a new one will be spawned to take its place in the pool. Tasks that are submitted when all pooled threads are busy will be held until a thread is freed if the pool has allocated its assigned number of threads already.

Parameters
nThreadsThe number of threads to assign as the max for the new ExecutorService.
threadFactoryInstance of a ThreadFactory that will be used by the Executor to spawn new worker threads. This parameter cannot be NULL.
Returns
pointer to a new ExecutorService that is owned by the caller.
Exceptions
NullPointerExceptionif threadFactory is NULL.
IllegalArgumentExceptionif nThreads is less than or equal to zero.
static ExecutorService* decaf::util::concurrent::Executors::newSingleThreadExecutor ( )
static

Creates an Executor that uses a single worker thread operating off an unbounded queue owned by the executor.

If the Executor's single thread should terminate for some reason such as failure during the execution of a task, a new Thread will be created if the Executor has not been shutdown and there are more tasks in the queue. The Executor returned from this method is owned by the caller but unlike the Executor returned from the method newFixedThreadPool(1) this one cannot be reconfigurable to use more threads later on.

Returns
a new Executor pointer that is owned by the caller.
static ExecutorService* decaf::util::concurrent::Executors::newSingleThreadExecutor ( ThreadFactory threadFactory)
static

Creates an Executor that uses a single worker thread operating off an unbounded queue owned by the executor.

If the Executor's single thread should terminate for some reason such as failure during the execution of a task, a new Thread will be created if the Executor has not been shutdown and there are more tasks in the queue. The Executor returned from this method is owned by the caller but unlike the Executor returned from the method newFixedThreadPool(1) this one cannot be reconfigurable to use more threads later on.

Parameters
threadFactoryInstance of a ThreadFactory that will be used by the Executor to spawn new worker threads. This parameter cannot be NULL and ownership passes to the Executor.
Returns
a new Executor pointer that is owned by the caller.
Exceptions
NullPointerExceptionif threadFactory is NULL.
static ExecutorService* decaf::util::concurrent::Executors::unconfigurableExecutorService ( ExecutorService executor)
static

Returns a new ExecutorService derived instance that wraps and takes ownership of the given ExecutorService pointer.

The returned ExecutorService delegates all calls to the wrapped ExecutorService instance but does not allow any configuration changes. This method provides a means of locking an ExecutorService instance configuration and prevents changes that might be accomplished with casting.

Parameters
executorThe ExecutorService pointer to wrap and take ownership of.
Returns
a new ExecutorService pointer that is owned by the caller.
Exceptions
NullPointerExceptionif ExecutorService is NULL.

Friends And Related Function Documentation


The documentation for this class was generated from the following file: