[concurrency-interest] ThreadPoolExecutor.afterExecute(Runnable r, Throwable t) is not behaving as per documentation

Joe Bowbeer joe.bowbeer at gmail.com
Thu May 4 06:43:13 EDT 2006


On 5/3/06, Jagadheeswar Reddy <reddyj at gmail.com> wrote:
>
> I have created a runnable task and deliberately created an unchecked
> exception in my run method.
>
> My class TaskExecutor extends ThreadPoolExecutor  and overrides
> afterExecute method .
>
> When I check for Throwable object in this method, it is still null, inspite
> of throwing unchecked exception in run method
>

The ThreadPool is "executing" a FutureTask rather than a Runnable, and
FutureTask is catching the exception:

    public boolean scheduleTask(Runnable r) {
        Future<Object> resultFetcher;
        Object result = "hello runnable executed successfully";
        resultFetcher =submit(r, result);
        return true;
    }

Try this:

    public boolean scheduleTask(Runnable r) {
        execute(r);
        return true;
    }

--Joe



More information about the Concurrency-interest mailing list