Main Page   Namespace List   Class Hierarchy   Compound List   Namespace Members   Compound Members  

Executor Class Reference

#include <Executor.h>

Inheritance diagram for Executor:

Cancelable Waitable NonCopyable ConcurrentExecutor PoolExecutor SynchronousExecutor ThreadedExecutor List of all members.

Public Methods

virtual ~Executor () throw ()
 Destroy an Executor.

virtual void execute (const RunnableHandle &task)=0
void execute (Runnable *task)
virtual void cancel ()=0
virtual void wait ()=0
virtual bool wait (unsigned long)=0

Detailed Description

Author:
Eric Crahen <crahen@cse.buffalo.edu>
Date:
<2002-06-04T07:49:11-0400>
Version:
2.2.2
Execeutors are an implementation of the Executor pattern. This is a more versatile construct than a thread pool. I have written a short paper describing this pattern.

Executors abstract the knowledge of how, where and when to run a task, from the task itself. They are quite versatile objects. Runnable objects can be submitted to an Executor and they will be run by the Executor at some point.

Executors do not need to be joined. They simply need to be cancel()ed at some point before the termination of your program.

An Executor implements the Cancelable interface, giving you some control over the lifetime of the Executor.

Disabling

Cancelling an Executor has the effect of preparing the Executor to shutdown, disabling it. An Executor that has been cancel()ed will no longer accept new tasks.

Disabling an Executor does not discard the tasks it has previously been assigned. Those tasks will all be executed and are not lost.

Exiting

An Executor will exit only after it has been cancel()ed. When a cancel()ed Executor depletes the tasks in its Queue, it will allow its threads to exit. If it is not cancel()ed, its threads will run indefnently, which will interfere with the clean termination of your program.

See also:
Cancelable
An Executor implements the Waitable interface, giving you a way to interact with it.

Waiting

For an Executor, waiting means waiting for the current batch of tasks to be serviced. A thread that wait()s on an Executor will be blocked until all of its enqueued tasks are being serviced.

An Executor can be wait()ed on many times. The completion of a wait() does not neccessarily mean the Executor is done running tasks and its lifetime is about to come to an end. It simply means that it is about to become idle.

See also:
Waitable
Cancel()ing and Wait()ing on an Executor will provide a way for an application to detect when an Executor is about to come to the end of its lifetime. A cancel()ed Executor won't accept more tasks, so when the wait() completes you will know that it's pretty much done doing it job.


Member Function Documentation

virtual void cancel   [pure virtual]
 

Stop the execution of additonal tasks by this Executor. A cancel()ed Executor will complete the task that are pending, or executing, but it will not accept any new tasks.

Exceptions:
InterruptedException 
Postcondition:
the Executor no longer accepts new tasks.

Implements Cancelable.

Implemented in ConcurrentExecutor, PoolExecutor, SynchronousExecutor, and ThreadedExecutor.

void execute Runnable   task [inline]
 

Convience method

See also:
Executor::execute(const RunnableHandle&)

Reimplemented in ConcurrentExecutor, PoolExecutor, SynchronousExecutor, and ThreadedExecutor.

virtual void execute const RunnableHandle &    task [pure virtual]
 

Submit a light wieght task to an Executor.

Parameters:
task  - command that will be executed
Exceptions:
Synchronization_Exception  thrown is some other error occurs.

Implemented in ConcurrentExecutor, PoolExecutor, SynchronousExecutor, and ThreadedExecutor.

virtual bool wait unsigned    long [pure virtual]
 

Wait for all pending and currently executing tasks to complete or or the given amount of time to expire. This method will block the calling thread, for an definite amount of time, until no more tasks are available and the Executor is about to become idle.

However, this method does not garuntee that an Executor is finished executing tasks. It's possible for more tasks to be submitted after a wait()ing thread has been awakened. In order to wait() until an Executor is done running tasks for good, the Executor should first be cancel()ed.

Parameters:
timeout  unsigned long - maximum amount of time (milliseconds) to wait() for an Executor.
Returns :
true if the wait() completes in the given amount of time; otherwise false.
Exceptions:
Interrupted_Exception  a wait() can be aborted prematurely by interrupt()ing a wait()ing thread.
Synchronization_Exception  throw if there is some other error.

Reimplemented from Waitable.

Implemented in ConcurrentExecutor, PoolExecutor, SynchronousExecutor, and ThreadedExecutor.

virtual void wait   [pure virtual]
 

Wait for all pending and currently executing tasks to complete. This method will block the calling thread, for an indefinite amount of time, until no more tasks are available and the Executor is about to become idle.

However, this method does not garuntee that an Executor is finished executing tasks. It's possible for more tasks to be submitted after a wait()ing thread has been awakened. In order to wait() until an Executor is done running tasks for good, the Executor should first be cancel()ed.

Exceptions:
Interrupted_Exception  a wait() can be aborted prematurely by interrupt()ing a wait()ing thread.
Synchronization_Exception  throw if there is some other error.

Reimplemented from Waitable.

Implemented in ConcurrentExecutor, PoolExecutor, SynchronousExecutor, and ThreadedExecutor.


The documentation for this class was generated from the following file:
Generated on Tue Aug 27 07:43:11 2002 for ZThread by doxygen1.2.17