Skip to content

Commit 3561c0a

Browse files
committed
Add notes
1 parent 81a4c31 commit 3561c0a

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
All about Multi-threading and Concurrent programming in Java. Simple and easy to understand code examples for most of the Concurrent APIs provided by Java.
44

55
#### All about Threads
6+
- [Motivation - Why do we need Threads?](./notes/threads-motivation.md)
67
- [Threads in Java](./src/com/codecafe/concurrency/thread)
78
- [Creating Threads](./src/com/codecafe/concurrency/thread/basics/designathread/creating-threads.md)
89
- [Thread States](./src/com/codecafe/concurrency/thread/basics/designathread/thread-states.md)

images/responsiveness.png

18.6 KB
Loading

notes/threads-motivation.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
## Motivation - Why do we need Threads?
2+
3+
1. **[Responsiveness](#responsiveness---concurrency)**
4+
2. **[Performance](#performance---parallelism)**
5+
6+
## Responsiveness - Concurrency
7+
8+
### Examples of Poor Responsiveness
9+
10+
- Waiting for Customer Support
11+
- Late response from a person
12+
- No feedback from an application
13+
14+
![Responsiveness](../images/responsiveness.png)
15+
16+
- Responsiveness can be achieved by using multiple threads, with a separate thread for each task.
17+
- Generally very hard to achieve otherwise.
18+
19+
> By multi-tasking quickly between threads, the CPU can create an illusion that all the tasks are executing at the same time.
20+
21+
The term we use for this kind of multi-tasking is **concurrency**.
22+
23+
We don't need multiple cores to achieve concurrency. Even with one core, we can create responsive applications by using multiple threads.
24+
25+
## Performance - Parallelism
26+
27+
- We can create an *illusion* of multiple tasks executing in parallel using just a single core.
28+
- With **multiple cores**, we can truly run tasks completely in parallel.
29+
30+
**Performance - Impact**
31+
- Completing a complex task much faster
32+
- Finish more work in the same period of time
33+
- For high-scale services:
34+
- Fewer machines
35+
- Less money spent on hardware

0 commit comments

Comments
 (0)