6.1 The Threadable Task API

The methods used for managing threadable tasks are provided by the standard reactor interface (Reactor), as defined in the Reaction API package. The full set of methods used for threadable task management are shown in Listing 6.1.


\begin{listing}
% latex2html id marker 1648\begin{small}\begin{verbatim}pack...
...nd{verbatim} \end{small}\caption{Reactor Thread Control Interface}
\end{listing}

The reactor interface methods provide support for running a threadable task in a new thread (runThread) and for cancelling a threadable task which is already running (cancelThread). In each case a single threadable task object is passed as the primary parameter, while the runThread method also passes in a generically typed input data parameter. Threadable task objects are defined as those which implement the Threadable interface as shown in Listing 6.2.


\begin{listing}
% latex2html id marker 1661\begin{small}\begin{verbatim}pack...
...verbatim} \end{small}\caption{The Threadable Interface Definition}
\end{listing}

The only method required by the Threadable interface is the run method. This takes a data object of generic type <T> as its parameter, which will be the same data object originally passed to the reactor's runThread method. The run method must eventually return a data object of generic type <U> or throw an exception, but there is no limitation on the amount of time which it may take to run.