The process of cancelling a running threadable task makes use of the underlying Java threads API for interrupting blocked threads. When the reactor's cancelThread method is called for a given threadable task object, the standard interrupt method is called on the underlying Java thread. This means that the blocked thread will be interrupted, throwing an exception of type InterruptedException. This exception will then be passed back via the threadable's deferred errback chain using the standard deferred error handling model.
The cancellation of threadable tasks may be demonstrated by making a small modification to the simple threadable test example previously used. The modified thread startup and cancellation code is shown in Listing 6.9. This results in the console output given in Listing 6.10, which clearly demonstrates the generation of the InterruptedException errback. The full version of this example is included in the thread examples package as ThreadableCancelExample.