Use cases
- Limit the number of parallel tasks of a similar nature that are executed at the same time.
- Example: Ensure that not more than 3 calls to an external service are made at the same time.
Why not ...
... use Executors.newFixedThreadPool
Because it creates new threads. This proposition is an Executor that limits without creating any new thread. The thread pool already exist and we want to use it. In the end, the tasks are dispatched to an existing Executor (which does not have to be a pool, but is the typical use).
Specifications
- Based on an existing executor (composite)
- Receive the number of parallel task to be executed at construction time.
Use cases
Why not ...
... use
Executors.newFixedThreadPoolBecause it creates new threads. This proposition is an Executor that limits without creating any new thread. The thread pool already exist and we want to use it. In the end, the tasks are dispatched to an existing Executor (which does not have to be a pool, but is the typical use).
Specifications