activemq-cpp-3.6.0
|
An object that executes submitted decaf.lang.Runnable tasks. More...
#include <src/main/decaf/util/concurrent/Executor.h>
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. |
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.
|
inlinevirtual |
|
pure 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 |
Implemented in decaf::util::concurrent::ThreadPoolExecutor.
|
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.
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 |
Implemented in decaf::util::concurrent::ThreadPoolExecutor.