Commit 13e5635
committed
docs(concurrency): add detailed notes and examples on Executors Framework in Java
WHAT was added:
- Theory section explaining Executors Framework (introduced in Java 5, part of java.util.concurrent).
- Covered key motivations:
• Efficient thread pooling (reuse threads instead of creating new ones).
• Reduces thread creation overhead.
• Provides pooling strategies and automatic lifecycle handling.
- Breakdown of core components:
• Executor (basic interface with execute()).
• ExecutorService (extends Executor, lifecycle + Future support).
• Executors (factory class with pool creation methods).
• Future (for async computation results).
- Table summarizing different thread pools:
• newFixedThreadPool
• newCachedThreadPool
• newSingleThreadExecutor
• newScheduledThreadPool
- Example 1: FixedThreadPool → shows 5 tasks running on 3 threads, with thread reuse.
- Example 2: ScheduledThreadPool → schedules a task with delay.
WHY this matters:
- Executors framework is the backbone of Java concurrency.
- Simplifies thread management, avoids boilerplate, prevents resource leaks.
- Provides different strategies suitable for I/O-bound, CPU-bound, or scheduled tasks.
- Using thread pools leads to more scalable and performant applications.
HOW it works:
- Executors.newFixedThreadPool(n) creates a pool of n reusable threads.
- Tasks beyond n wait in a queue until threads become free.
- Executors.newScheduledThreadPool(n) allows delayed/periodic execution.
- executor.shutdown() ensures resources are released properly.
HINTS:
- Always call shutdown() or shutdownNow() after using ExecutorService.
- FixedThreadPool → stable concurrency level (good for CPU-bound).
- CachedThreadPool → dynamic scaling (good for many short-lived tasks).
- SingleThreadExecutor → guarantees sequential execution.
- ScheduledThreadPool → replacement for Timer with better concurrency support.
KEYWORDS:
executors executorservice future threadpool scheduledexecutorservice concurrency java.
Signed-off-by: https://github.com/Someshdiwan <[email protected]>1 parent d286412 commit 13e5635
File tree
1 file changed
+3
-4
lines changed- Section19MultiThreading/ThreadPooling/ExecutorsFramework/src/TXTFiles
1 file changed
+3
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | 7 | | |
9 | 8 | | |
10 | 9 | | |
| |||
20 | 19 | | |
21 | 20 | | |
22 | 21 | | |
23 | | - | |
| 22 | + | |
24 | 23 | | |
25 | 24 | | |
26 | 25 | | |
| |||
80 | 79 | | |
81 | 80 | | |
82 | 81 | | |
83 | | - | |
| 82 | + | |
0 commit comments