Skip to content

Commit 93090f8

Browse files
committed
docs(concurrency): add detailed theory on Executors Framework in Java
WHAT was added: - Comprehensive explanation of the Executors Framework (introduced in Java 5, part of java.util.concurrent). - Reasons for using Executors: • Efficient thread management (reuse threads, reduce overhead). • Optimized performance (prevent thread explosion). • Better control (limit active threads, execution policies). • Simplified multi-threading (removes manual Thread handling). - Core components explained: • Executor → base interface with execute(Runnable). • ExecutorService → extends Executor with lifecycle & result retrieval. • Executors → utility class with factory methods for thread pools. • Future → handle asynchronous computation results. - Table summarizing thread pool types: • FixedThreadPool → bounded concurrency. • CachedThreadPool → dynamic, unbounded scaling. • SingleThreadExecutor → sequential execution guarantee. • ScheduledThreadPool → delayed & periodic task execution. - Advantages list: performance, resource management, scalability, flexibility. WHY this matters: - Provides foundational knowledge for Java concurrency. - Explains WHY Executors are preferred over manual thread creation. - Highlights which pool type to use in different scenarios (CPU-bound, I/O-bound, sequential, scheduled). HINTS: - Always call shutdown() on ExecutorService to release resources. - FixedThreadPool → good for predictable, limited parallelism. - CachedThreadPool → best for many short-lived async tasks. - SingleThreadExecutor → ensures order and single-thread execution. - ScheduledThreadPool → modern replacement for Timer/TimerTask. KEYWORDS: executors executorservice future threadpool scheduledthreadpool java concurrency theory. Signed-off-by: https://github.com/Someshdiwan <[email protected]>
1 parent 13e5635 commit 93090f8

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
Executors Framework in Java (Thread Pooling) – Theory
22

3-
The Executors Framework in Java is a high-level concurrency framework introduced in Java 5
3+
The Executor Framework in Java is a high-level concurrency framework introduced in Java 5
44
(part of java.util.concurrent).
55

66
It provides a structured way to manage and control thread execution using thread pools,
7-
improving efficiency and performance in multi-threaded applications.
7+
improving efficiency and performance in multithreaded applications.
88

99
Why Use the Executors Framework?
1010

@@ -24,29 +24,25 @@ Why Use the Executors Framework?
2424
- Eliminates the complexity of manually handling `Thread` objects.
2525
- Provides built-in mechanisms for handling scheduled and asynchronous tasks.
2626

27-
Core Components of Executors Framework**
27+
Core Components of Executors Framework:
2828

2929
1. Executor Interface:
30-
3130
- The base interface for task execution.
3231
- Defines the execute(Runnable command) method for running tasks asynchronously.
3332

3433
2. ExecutorService Interface
35-
3634
- Extends Executor and provides advanced methods for thread management.
3735
- Supports submitting tasks, shutting down the pool, and retrieving results.
3836

3937
3. Executors Class
40-
4138
- A utility class that provides factory methods to create different types of thread pools.
4239
- Helps in managing thread creation without manually handling Thread objects.
4340

4441
4. Future Interface
45-
4642
- Represents the result of an asynchronous computation.
4743
- Allows checking if the task is complete and retrieving the result once available.
4844

49-
Types of Thread Pools in Executors Framework
45+
Types of Thread Pools in Executors Framework:
5046

5147
| Thread Pool Type | Description | Use Case |
5248
|---------------------------------------------------------|-----------------------------------------------------------|-------------------------------------------------------------------|
@@ -56,9 +52,8 @@ Types of Thread Pools in Executors Framework
5652
| Scheduled Thread Pool (newScheduledThreadPool(n)) | Executes tasks after a fixed delay or periodically. | Ideal for scheduled and recurring tasks. |
5753

5854
Advantages of the Executors Framework:
59-
60-
✔ Improved Performance** – Reduces thread creation overhead by reusing existing threads.
61-
✔ Better Resource Management – Limits thread count to prevent excessive CPU and memory usage.
62-
✔ Simplifies Thread Management – Eliminates the need for manual thread handling.
63-
✔ Scalability – Adapts to workload demands efficiently.
64-
✔ Flexibility – Provides different thread pool strategies for various use cases.
55+
Improved Performance – Reduces thread creation overhead by reusing existing threads.
56+
Better Resource Management – Limits thread count to prevent excessive CPU and memory usage.
57+
Simplifies Thread Management – Eliminates the need for manual thread handling.
58+
Scalability – Adapts to workload demands efficiently.
59+
Flexibility – Provides different thread pool strategies for various use cases.

0 commit comments

Comments
 (0)