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,
const E &  result,
bool  owns = true 
) [inline, static]

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

Parameters:
task The Runnable task that is to be executed.
result The value that is returned from the callable upon completion.
owns Does 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:
NullPointerException if the Runnable task is NULL

References NULL.

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

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

Parameters:
task The Runnable task that is to be executed.
owns Does 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:
NullPointerException if 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,
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:
nThreads The number of threads to assign as the max for the new ExecutorService.
threadFactory Instance 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:
NullPointerException if threadFactory is NULL.
IllegalArgumentException if nThreads is less than or equal to zero.
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:
nThreads The 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:
IllegalArgumentException if nThreads is less than or equal to zero.
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:
threadFactory Instance 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:
NullPointerException if threadFactory is NULL.
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::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:
executor The ExecutorService pointer to wrap and take ownership of.
Returns:
a new ExecutorService pointer that is owned by the caller.
Exceptions:
NullPointerException if ExecutorService is NULL.

Friends And Related Function Documentation


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

Generated on 1 Dec 2014 for activemq-cpp-3.8.2 by  doxygen 1.6.1