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

An object that executes submitted decaf.lang.Runnable tasks. More...

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

Inheritance diagram for decaf::util::concurrent::Executor:

Public Member Functions

virtual ~Executor ()
virtual void execute (decaf::lang::Runnable *command)=0
 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 *command, bool takeOwnership)=0
 Executes the given command at some time in the future.

Detailed Description

An object that executes submitted decaf.lang.Runnable tasks.

This interface provides a way of decoupling task submission from the mechanics of how each task will be run, including details of thread use, scheduling, etc. An Executor is normally used instead of explicitly creating threads. For example, rather than invoking new Thread(new(RunnableTask())).start() for each of a set of tasks, you might use:

Executor executor = anExecutor;
executor->execute( new RunnableTask1() );
executor->execute( new RunnableTask2() );
...

However, the Executor interface does not strictly require that execution be asynchronous. In the simplest case, an executor can run the submitted task immediately in the caller's thread:

class DirectExecutor : public Executor {
public:
    void execute( Runnable* r ) {
        r->run();
    }
}

More typically, tasks are executed in some thread other than the caller's thread. The executor below spawns a new thread for each task.

class ThreadPerTaskExecutor : public Executor {
public:
    std::vector<Thread*gt; threads;
    void execute( Runnable* r ) {
        threads.push_back( new Thread( r ) );
        threads.rbegin()->start();
    }
}

The Executor implementations provided in this package implement decaf.util.concurrent.ExecutorService, which is a more extensive interface. The decaf.util.concurrent.ThreadPoolExecutor class provides an extensible thread pool implementation. The decaf.util.concurrentExecutor class provides convenient factory methods for these Executors.

Since
1.0

Constructor & Destructor Documentation

virtual decaf::util::concurrent::Executor::~Executor ( )
inlinevirtual

Member Function Documentation

virtual void decaf::util::concurrent::Executor::execute ( decaf::lang::Runnable command)
pure virtual

This method is the same as calling the two param execute method and passing true as the second argument.

Parameters
commandThe runnable task to be executed.
Exceptions
RejectedExecutionExceptionif this task cannot be accepted for execution.
NullPointerExceptionif command is null

Implemented in decaf::util::concurrent::ThreadPoolExecutor.

virtual void decaf::util::concurrent::Executor::execute ( decaf::lang::Runnable command,
bool  takeOwnership 
)
pure 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.

Parameters
commandThe runnable task to be executed.
takeOwnershipIndicates if the Executor should assume ownership of the task and delete the pointer once the task has completed.
Exceptions
RejectedExecutionExceptionif this task cannot be accepted for execution.
NullPointerExceptionif command is null

Implemented in decaf::util::concurrent::ThreadPoolExecutor.


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