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.
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.
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.