Skip to content

Commit eb7c40c

Browse files
committed
Refactor notes and README.md
1 parent 3561c0a commit eb7c40c

File tree

13 files changed

+25
-19
lines changed

13 files changed

+25
-19
lines changed

README.md

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,32 @@
11
# Multithreading and Concurrency in Java
22

3-
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.
3+
All about Multi-threading and Concurrent programming in Java.
4+
Simple and easy to understand code examples for most of the Concurrent APIs provided by Java.
45

56
#### All about Threads
67
- [Motivation - Why do we need Threads?](./notes/threads-motivation.md)
78
- [Threads in Java](./src/com/codecafe/concurrency/thread)
8-
- [Creating Threads](./src/com/codecafe/concurrency/thread/basics/designathread/creating-threads.md)
9-
- [Thread States](./src/com/codecafe/concurrency/thread/basics/designathread/thread-states.md)
9+
- [Creating Threads](./notes/creating-threads.md) using
10+
- [Runnable](./src/com/codecafe/concurrency/thread/basics/designathread/ThreadDemo.java)
11+
- [Thread class](./src/com/codecafe/concurrency/thread/basics/designathread/ThreadDemo.java)
12+
- [Callable](./src/com/codecafe/concurrency/thread/basics/designathread/CallableDemo.java)
13+
- [ExecutorService](notes/executorservice.md) - [[code](./src/com/codecafe/concurrency/executorservice/ExecutorServiceDemo.java)]
14+
- [Thread States](./notes/thread-states.md) - [[code](./src/com/codecafe/concurrency/thread/basics/designathread/ThreadStates.java)]
15+
- [Stop a Thread](./src/com/codecafe/concurrency/thread/basics/StopAThreadInMiddle.java)
1016
- [Thread Signalling](./src/com/codecafe/concurrency/threadsignalling)
11-
- [Daemon Thread](./src/com/codecafe/concurrency/thread/daemonthread/daemon-thread.md)
17+
- [Daemon Thread](./notes/daemon-thread.md) - [[code](./src/com/codecafe/concurrency/thread/daemonthread)]
1218

1319
#### Thread synchronization and locks
1420
- [The `synchronized` keyword](./src/com/codecafe/concurrency/_synchronized)
1521
- [Locks](./src/com/codecafe/concurrency/locks)
1622
- [Deadlock](./src/com/codecafe/concurrency/deadlock)
1723

1824
#### Concurrent APIs provided by Java
19-
- [ExecutorService](./src/com/codecafe/concurrency/executorservice/executorservice.md)
2025
- [BlockingQueue](./src/com/codecafe/concurrency/blockingqueue)
21-
- [Semaphore](./src/com/codecafe/concurrency/semaphore/semaphore.md)
22-
- [CountdownLatch](./src/com/codecafe/concurrency/countdownlatch/countdownlatch.md)
23-
- [CyclicBarrier](./src/com/codecafe/concurrency/cyclicbarrier/cyclicbarrier.md)
26+
- [Semaphore](./notes/semaphore.md) - [[code](./src/com/codecafe/concurrency/semaphore)]
27+
- [CountdownLatch](./notes/countdownlatch.md) - [[code](./src/com/codecafe/concurrency/countdownlatch/CountDownLatchDemo.java)]
28+
- [with time-out](./src/com/codecafe/concurrency/countdownlatch/timeout/TerminatingCountDownLatch.java)
29+
- [CyclicBarrier](./notes/cyclicbarrier.md) - [[code](./src/com/codecafe/concurrency/cyclicbarrier/CyclicBarrierDemo.java)]
30+
- [Need of CyclicBarrier](./src/com/codecafe/concurrency/cyclicbarrier/NeedOfCyclicBarrier.java)
2431
- [`atomic` variables](./src/com/codecafe/concurrency/_atomic)
25-
- [The `volatile` keyword](./src/com/codecafe/concurrency/_volatile/volatile-keyword.md)
32+
- [The `volatile` keyword](./src/com/codecafe/concurrency/_volatile/volatile-keyword.md) - [[code](./src/com/codecafe/concurrency/_volatile/VolatileDemo.java)]

notes/threads-motivation.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
## Motivation - Why do we need Threads?
22

3-
1. **[Responsiveness](#responsiveness---concurrency)**
4-
2. **[Performance](#performance---parallelism)**
3+
For two primary things:
54

6-
## Responsiveness - Concurrency
5+
1. **[Responsiveness](#responsiveness---achieved-by-concurrency)**
6+
2. **[Performance](#performance---achieved-by-parallelism)**
7+
8+
## Responsiveness - achieved by Concurrency
79

810
### Examples of Poor Responsiveness
911

@@ -22,7 +24,7 @@ The term we use for this kind of multi-tasking is **concurrency**.
2224

2325
We don't need multiple cores to achieve concurrency. Even with one core, we can create responsive applications by using multiple threads.
2426

25-
## Performance - Parallelism
27+
## Performance - achieved by Parallelism
2628

2729
- We can create an *illusion* of multiple tasks executing in parallel using just a single core.
2830
- With **multiple cores**, we can truly run tasks completely in parallel.

src/com/codecafe/concurrency/thread/basics/StopAThreadInMiddle.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public void run() {
77
for (; ; ) {
88
// Returns true if the thread is interrupted
99
if (interrupted()) {
10-
// You are supposed to rollback or reverse the operation in progress and stop
10+
// You are supposed to roll back or reverse the operation in progress and stop
1111
System.out.println("Thread is interrupted hence stopping...");
1212
// Terminates the loop
1313
break;

src/com/codecafe/concurrency/thread/basics/designathread/CallableDemo.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
package com.codecafe.concurrency.thread.basics.designathread;
22

3-
import java.util.concurrent.Callable;
4-
import java.util.concurrent.ExecutionException;
5-
import java.util.concurrent.ExecutorService;
6-
import java.util.concurrent.Executors;
7-
import java.util.concurrent.Future;
3+
import java.util.concurrent.*;
84

95
class MyMath {
106
public static int add(int a, int b) {
@@ -28,6 +24,7 @@ public Integer call() throws Exception {
2824
int result = x + y;
2925
return result;
3026
}
27+
3128
}
3229

3330
public class CallableDemo {

0 commit comments

Comments
 (0)