Implementing a long running threadable task is just an exercise in implementing the run method of the Threadable interface. Unlike code which runs in the context of the main reactor thread - such as timer, signal and deferrable callbacks - threadable tasks are allowed to block. In the example shown in Listing 6.3 there is a blocking call to the Thread.sleep method which halts the execution of the threadable task for 1 second.
Assuming that the long running task is not interrupted while sleeping, it will return a generically typed data object as specified by the interface definition for the run method. In order to run the threadable task, the runThread method on the Reactor interface is invoked as shown in Listing 6.4.
The runThread method returns a deferred event object which will have its callbacks executed when the threadable task's run method returns. The callback parameter passed up the callback chain will be the generically typed data object which is returned by the threadable task's run method. In order to process the callbacks, the simple deferrable callback handler previously presented in Section 5.2 may be used. The full implementation of this example may be found in the thread examples package as ThreadableExample1.