Skip to content

Commit 02d41b8

Browse files
author
Daniel
committed
Concurrency: foundational
1 parent c806224 commit 02d41b8

12 files changed

Lines changed: 3064 additions & 12 deletions

TOPICS_PLAN.md

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,37 @@ src/main/java/org/nkcoder/
3737
|--------------|--------|-------------------------------|------------------------------------------|
3838
| preview/ | [x] | StructuredConcurrencyExample | StructuredTaskScope, Joiner (5th preview)|
3939

40-
**Interview Priority (Completed):**
40+
**Medium:**
4141

4242
| Sub-package | Status | Examples | Concepts |
4343
|-------------------------|--------|---------------------------------------------------------------|--------------------------------------------|
4444
| executors/ | [x] | ExecutorServiceExample, CompletableFutureExample | ExecutorService, async programming |
4545
| atomic/ | [x] | AtomicIntegerExample, AtomicReferenceExample | Atomic classes, CAS operations |
4646
| concurrent_collections/ | [x] | ConcurrentHashMapExample, CopyOnWriteListExample | Thread-safe collections |
4747

48-
**Foundational (To Add Later):**
48+
**Foundational (Learn for interviews & legacy code, prefer modern alternatives for new code):**
4949

50-
| Sub-package | Status | Examples | Concepts |
51-
|-------------------------|--------|---------------------------------------------------------------|--------------------------------------------|
52-
| thread/ | [ ] | ThreadExample, DaemonThreadExample | Thread creation, lifecycle, daemon threads |
53-
| synchronization/ | [ ] | SynchronizedExample, VolatileExample, WaitNotifyExample | synchronized, volatile, wait/notify |
54-
| locks/ | [ ] | ReentrantLockDemo, ReadWriteLockExample | ReentrantLock, ReadWriteLock |
55-
| utilities/ | [ ] | CountDownLatchExample, SemaphoreExample | Synchronization utilities |
50+
| Sub-package | Status | Examples | Java 25 Recommendation |
51+
|------------------|--------|---------------------------------------------------------------|---------------------------------------------|
52+
| thread/ | [x] | ThreadExample, DaemonThreadExample | ⚠️ Use ExecutorService or virtual threads |
53+
| synchronization/ | [x] | SynchronizedExample, VolatileExample, WaitNotifyExample | ⚠️ Prefer Atomic*, locks, BlockingQueue |
54+
| locks/ | [x] | ReentrantLockExample, ReadWriteLockExample | ✅ Still relevant for advanced locking |
55+
| utilities/ | [x] | CountDownLatchExample, SemaphoreExample | ✅ Semaphore useful; Latch → structured concurrency |
56+
57+
**Why learn foundational concurrency?**
58+
- Interview questions still focus heavily on these concepts
59+
- Legacy codebases use them extensively
60+
- Understanding primitives helps debug modern abstractions
61+
- Modern APIs (virtual threads, structured concurrency) build on these
62+
63+
**Rule of thumb for new Java 25 code:**
64+
65+
```
66+
1st choice: Virtual threads + simple blocking code
67+
2nd choice: ConcurrentHashMap, Atomic*, CompletableFuture
68+
3rd choice: ReentrantLock, Semaphore (when needed)
69+
Last resort: Raw threads, synchronized, wait/notify
70+
```
5671

5772
---
5873

@@ -168,7 +183,7 @@ src/main/java/org/nkcoder/
168183

169184
| Topic | Status | Progress |
170185
|--------------|-------------|----------|
171-
| concurrency | In Progress | 9/18 |
186+
| concurrency | Complete | 18/18 |
172187
| collections | Complete | 6/6 |
173188
| streams | Complete | 4/4 |
174189
| fp | Complete | 6/6 |
@@ -178,4 +193,4 @@ src/main/java/org/nkcoder/
178193
| generics | Not Started | 0/5 |
179194
| exceptions | Not Started | 0/4 |
180195
| io | Not Started | 0/3 |
181-
| **Total** | | **31/63**|
196+
| **Total** | | **40/63**|

docs/troubleshooting.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,21 @@ Starting a Gradle Daemon, 1 incompatible and 1 stopped Daemons could not be reus
66

77
BUILD SUCCESSFUL in 3s
88
1 actionable task: 1 executed
9-
```
9+
```
10+
11+
## Preview features
12+
13+
Need to add the following config to build.gradle.kts
14+
15+
```java
16+
// For preview features
17+
tasks.withType<JavaCompile> {
18+
options.compilerArgs.addAll(listOf("--enable-preview", "-Xlint:preview"))
19+
}
20+
21+
tasks.withType<JavaExec> {
22+
jvmArgs("--enable-preview")
23+
}
24+
```
25+
26+
Intellij Idea: Project Structure -> Project Settings -> Project: language level (25 preview).

src/main/java/org/nkcoder/concurrency/atomic/AtomicIntegerExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*/
2222
public class AtomicIntegerExample {
2323

24-
public static void main(String[] args) throws Exception {
24+
static void main(String[] args) throws Exception {
2525
whyAtomicNeeded();
2626
basicOperations();
2727
atomicIncrementDecrement();

0 commit comments

Comments
 (0)