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.
|
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
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.
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.
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
-
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. |
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::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.
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. |
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
-
- Returns
- a new ExecutorService pointer that is owned by the caller.
- Exceptions
-
Friends And Related Function Documentation
The documentation for this class was generated from the following file: