Skip to content

Commit 87093cf

Browse files
committed
Update README.md
1 parent 6cb5b4a commit 87093cf

File tree

4 files changed

+23
-73
lines changed

4 files changed

+23
-73
lines changed

thread-pool/README.md

+23-11
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,38 @@ tags:
99
---
1010

1111
## Intent
12-
It is often the case that tasks to be executed are short-lived and
13-
the number of tasks is large. Creating a new thread for each task would make
14-
the system spend more time creating and destroying the threads than executing
15-
the actual tasks. Thread Pool solves this problem by reusing existing threads
16-
and eliminating the latency of creating new threads.
12+
13+
It is often the case that tasks to be executed are short-lived and the number of tasks is large.
14+
Creating a new thread for each task would make the system spend more time creating and destroying
15+
the threads than executing the actual tasks. Thread Pool solves this problem by reusing existing
16+
threads and eliminating the latency of creating new threads.
1717

1818
## Explanation
19+
1920
Real world example
2021

21-
> We have a large number of relatively short tasks at hand. We need to peel huge amounts of potatoes and serve mighty amount of coffee cups. Creating a new thread for each task would be a waste so we establish a thread pool.
22+
> We have a large number of relatively short tasks at hand. We need to peel huge amounts of potatoes
23+
> and serve mighty amount of coffee cups. Creating a new thread for each task would be a waste so we
24+
> establish a thread pool.
2225
2326
In plain words
2427

2528
> Thread Pool is a concurrency pattern where threads are allocated once and reused between tasks.
2629
2730
Wikipedia says
2831

29-
> In computer programming, a thread pool is a software design pattern for achieving concurrency of execution in a computer program. Often also called a replicated workers or worker-crew model, a thread pool maintains multiple threads waiting for tasks to be allocated for concurrent execution by the supervising program. By maintaining a pool of threads, the model increases performance and avoids latency in execution due to frequent creation and destruction of threads for short-lived tasks. The number of available threads is tuned to the computing resources available to the program, such as a parallel task queue after completion of execution.
32+
> In computer programming, a thread pool is a software design pattern for achieving concurrency of
33+
> execution in a computer program. Often also called a replicated workers or worker-crew model,
34+
> a thread pool maintains multiple threads waiting for tasks to be allocated for concurrent
35+
> execution by the supervising program. By maintaining a pool of threads, the model increases
36+
> performance and avoids latency in execution due to frequent creation and destruction of threads
37+
> for short-lived tasks. The number of available threads is tuned to the computing resources
38+
> available to the program, such as a parallel task queue after completion of execution.
3039
3140
**Programmatic Example**
3241

33-
Let's first look at our task hierarchy. We have a base class and then concrete CoffeeMakingTask and PotatoPeelingTask.
42+
Let's first look at our task hierarchy. We have a base class and then concrete `CoffeeMakingTask`
43+
and `PotatoPeelingTask`.
3444

3545
```java
3646
public abstract class Task {
@@ -88,8 +98,8 @@ public class PotatoPeelingTask extends Task {
8898
}
8999
```
90100

91-
Next we present a runnable Worker class that the thread pool will utilize to handle all the potato peeling and coffee
92-
making.
101+
Next we present a runnable `Worker` class that the thread pool will utilize to handle all the potato
102+
peeling and coffee making.
93103

94104
```java
95105
public class Worker implements Runnable {
@@ -156,9 +166,11 @@ Now we are ready to show the full example in action.
156166
```
157167

158168
## Class diagram
159-
![alt text](./etc/thread-pool.png "Thread Pool")
169+
170+
![alt text](./etc/thread_pool_urm.png "Thread Pool")
160171

161172
## Applicability
173+
162174
Use the Thread Pool pattern when
163175

164176
* You have a large number of short-lived tasks to be executed in parallel

thread-pool/etc/thread-pool.png

-14.4 KB
Binary file not shown.

thread-pool/etc/thread-pool.ucls

-62
This file was deleted.

thread-pool/etc/thread_pool_urm.png

29.4 KB
Loading

0 commit comments

Comments
 (0)