Introducing the Runnable
In the Threading package, the runnable family of classes includes the basic mechanisms used to create, control, and monitor the threads of execution within your application. The
RWThreadFunction class used in the example is a member of the runnable family;
Figure 2 shows its relationship to the other runnable classes.
All runnable objects have a start() member and a virtual run() member. The run() member defines the work or activity to be performed by the runnable object. The start() member defines the form of dispatching to be used in executing the run() member. The dispatching is performed either synchronously by executing within the calling thread, or asynchronously by creating a new thread. Regardless of the dispatching mechanism, the run() member is always executed as a consequence of calling start().
The
RWThreadFunction class used in the example is one of the asynchronous or
threaded runnable classes. Instances of this class create a new thread of execution when
start() is called. The
RWThreadFunction class uses a
functor to indicate to the new thread what to execute after it starts; in this case, the
hello() function.