Customizing the ThreadPoolExecutor class

The Executor framework is a mechanism that allows you to separate the thread creation from its execution. It's based on the Executor and ExecutorService interfaces with the ThreadPoolExecutor class that implements both interfaces. It has an internal pool of threads and provides methods that allow you to send two kinds of tasks for their execution in the pooled threads. These tasks are:

  • The Runnable interface to implement tasks that don't return a result
  • The Callable interface to implement tasks that return a result

In both cases, you only send the task to the executor. The executor uses one of its pooled threads or creates a new one to execute those tasks. The executor also decides the moment in which the ...

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.