Cover by Javier Fernández González

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

O'Reilly logo

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required