Each thread requires resources—CPU and memory. It means the number of threads must be controlled, and one way to do it is to create a fixed number of them—a pool. Besides, creating an object incurs an overhead that may be significant for some applications.
In this section, we will look into the Executor interfaces and their implementations provided in the java.util.concurrent package. They encapsulate thread management and minimize the time an application developer spends on writing the code related to threads' life cycles.
There are three Executor interfaces defined in the java.util.concurrent package:
- The base Executor interface: It has only one void execute(Runnable r) method in it.
- The ExecutorService interface: It extends Executor and adds four groups of methods that manage the life cycle of the worker threads and of the executor...