2015-08-13 23:54:40 +02:00
|
|
|
---
|
|
|
|
layout: pattern
|
|
|
|
title: Thread Pool
|
|
|
|
folder: thread-pool
|
2015-08-15 18:03:05 +02:00
|
|
|
permalink: /patterns/thread-pool/
|
2016-08-30 15:10:34 +02:00
|
|
|
pumlid: JSV14SCW30J0Lk82GFzq8uF6a1624IUx_UIPt-xHhMXK2TTN0zP-4pa_-UfeSSOMBzCWXbpceAxnCDZfmpUdAhjVbXO3uhPfyFw1q5oufZMdag3yFuUFl6Be5m00
|
2015-08-20 21:40:07 +02:00
|
|
|
categories: Concurrency
|
2015-12-28 15:52:44 +02:00
|
|
|
tags:
|
|
|
|
- Java
|
|
|
|
- Difficulty-Intermediate
|
2015-12-28 16:07:43 +02:00
|
|
|
- Performance
|
2015-08-13 23:54:40 +02:00
|
|
|
---
|
|
|
|
|
2016-01-03 21:14:30 +01:00
|
|
|
## Intent
|
|
|
|
It is often the case that tasks to be executed are short-lived and
|
2015-08-13 23:54:40 +02:00
|
|
|
the number of tasks is large. Creating a new thread for each task would make
|
|
|
|
the system spend more time creating and destroying the threads than executing
|
|
|
|
the actual tasks. Thread Pool solves this problem by reusing existing threads
|
|
|
|
and eliminating the latency of creating new threads.
|
|
|
|
|
|
|
|

|
|
|
|
|
2016-01-03 21:14:30 +01:00
|
|
|
## Applicability
|
|
|
|
Use the Thread Pool pattern when
|
2015-08-13 23:54:40 +02:00
|
|
|
|
2015-08-15 18:03:05 +02:00
|
|
|
* you have a large number of short-lived tasks to be executed in parallel
|