Controlling rejected tasks of an executor

When you want to finish the execution of an executor, you use the shutdown() method to indicate that it should finish. The executor waits for the completion of the tasks that are running or waiting for their execution, and then finishes its execution.

If you send a task to an executor between the shutdown() method and the end of its execution, the task is rejected, because the executor no longer accepts new tasks. The ThreadPoolExecutor class provides a mechanism, which is called when a task is rejected.

In this recipe, you will learn how to manage rejecting tasks in an executor that is implementing with RejectedExecutionHandler.

Getting ready

The example of this recipe has been implemented using the Eclipse ...

Get Java 7 Concurrency Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.