Introduction
Normally, when you implement a simple, concurrent Java application, you implement some Runnable
objects and then the corresponding Thread
objects. You control the creation, execution, and status of those threads in your program. Java 5 introduced an improvement with the Executor
and ExecutorService
interfaces and the classes that implement them (for example, the ThreadPoolExecutor
class).
The Executor framework separates the task creation and its execution. With it, you only have to implement the Runnable
objects and use an Executor
object. You send the Runnable
tasks to the executor and it creates, manages, and finalizes the necessary threads to execute those tasks.
Java 7 goes a step further and includes an additional implementation of the ExecutorService
interface oriented to a specific kind of problem. It's the fork/join framework.
This framework is designed to solve problems that can be broken into smaller tasks using the divide and conquer technique. Inside a task, you check...