Commit d286412
committed
docs(concurrency): add detailed notes and examples on Executors, ExecutorService, and ScheduledExecutorService
WHAT was added:
- Comprehensive explanation of the Executor Framework in Java.
- Clear breakdown of:
• Executors utility class (factory methods like newFixedThreadPool, newCachedThreadPool, etc.)
• ExecutorService interface (submit, invokeAll, invokeAny, shutdown, etc.)
• ScheduledExecutorService interface (schedule, scheduleAtFixedRate, scheduleWithFixedDelay).
- Comparison table showing differences in purpose, features, and usage.
- Example programs:
• ExecutorsExample → demonstrates fixed thread pool with 3 threads executing 5 tasks.
• ExecutorServiceExample → shows `submit()` with Callable and retrieving result via Future.
• ScheduledExecutorServiceExample → demonstrates scheduling tasks at fixed intervals.
WHY this matters:
- Simplifies understanding of Java’s concurrency abstractions.
- Highlights advantages of using thread pools over manual thread creation.
- Demonstrates task submission, scheduling, and lifecycle management in practice.
- Provides a quick reference for when to choose Executors vs ExecutorService vs ScheduledExecutorService.
HOW it works:
- Executors: Utility class, only creates thread pools.
- ExecutorService: Manages thread pools, executes tasks, supports results (Future).
- ScheduledExecutorService: Extends ExecutorService, adds scheduling for delayed/periodic tasks.
- Example outputs included to illustrate thread reuse and scheduling behavior.
HINTS:
- Always shut down ExecutorService to free resources (`shutdown()` or `shutdownNow()`).
- Use fixed thread pools to limit concurrency and cached pools for dynamic scaling.
- For periodic tasks, prefer `ScheduledExecutorService` instead of `Timer` (better thread safety).
- Use `Future.get()` carefully — it blocks until result is ready.
WHEN TO USE:
- Executors → quick creation of thread pools.
- ExecutorService → advanced task submission and result handling.
- ScheduledExecutorService → scheduling periodic or delayed tasks.
KEYWORDS:
executors executorservice scheduledexecutorservice threadpool future concurrency java.
Signed-off-by: https://github.com/Someshdiwan <[email protected]>1 parent 5d381e2 commit d286412
File tree
1 file changed
+15
-20
lines changed- Section19MultiThreading/ThreadPooling/ExecutorsFramework/src/TXTFiles
1 file changed
+15
-20
lines changedLines changed: 15 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
2 | 4 | | |
3 | | - | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
10 | | - | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
46 | | - | |
47 | | - | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | | - | |
55 | | - | |
| 54 | + | |
56 | 55 | | |
57 | 56 | | |
58 | 57 | | |
| |||
85 | 84 | | |
86 | 85 | | |
87 | 86 | | |
88 | | - | |
89 | 87 | | |
90 | 88 | | |
91 | | - | |
92 | 89 | | |
93 | 90 | | |
94 | 91 | | |
95 | 92 | | |
96 | | - | |
97 | | - | |
| 93 | + | |
98 | 94 | | |
99 | 95 | | |
100 | 96 | | |
101 | 97 | | |
102 | 98 | | |
103 | | - | |
| 99 | + | |
104 | 100 | | |
105 | | - | |
| 101 | + | |
106 | 102 | | |
107 | 103 | | |
108 | 104 | | |
109 | | - | |
110 | | - | |
| 105 | + | |
| 106 | + | |
111 | 107 | | |
112 | 108 | | |
113 | 109 | | |
| |||
133 | 129 | | |
134 | 130 | | |
135 | 131 | | |
136 | | - | |
| 132 | + | |
137 | 133 | | |
138 | 134 | | |
139 | 135 | | |
140 | | - | |
| 136 | + | |
141 | 137 | | |
142 | 138 | | |
143 | 139 | | |
| |||
148 | 144 | | |
149 | 145 | | |
150 | 146 | | |
151 | | - | |
152 | | - | |
| 147 | + | |
153 | 148 | | |
154 | 149 | | |
155 | | - | |
| 150 | + | |
0 commit comments