One advantage of using threadable tasks is that unlike `raw' threads there is a well defined way of handling exceptions which occur during execution. These are automatically caught by the Reaction framework and converted to deferred errback calls. The error condition may then be handled in the same manner as conventional deferred errbacks. An example of a long running task which generates an exception is shown in Listing 6.5.
In this example an exception is explicitly thrown by the threadable run method, and the generated exception object will be passed back via the deferred errback chain. The full implementation of this example is provided in the thread examples package as ThreadableExample2. This includes a deferrable callback handler which prints out the details of the generated exception, as shown in Listing 6.6.
It is worth noting from the debug log messages that additional worker threads are automatically created and destroyed in order to execute the threadable task code. These are standard Java threads which are managed within the reactor core as a dynamic thread pool. By reusing threads from the thread pool, the overhead of creating and destroying thread objects for each execution of a threadable task is much reduced.