Commit 356a3e4
committed
feat(executors): implement factorial computation using ExecutorService with fixed thread pool
WHAT was done:
- Replaced manual thread creation (Thread[] array + join logic) with ExecutorService.
- Used Executors.newFixedThreadPool(9) to manage 9 worker threads for factorial tasks.
- Submitted 9 factorial computations (1–9) via executorService.submit().
- Added graceful shutdown with executorService.shutdown() and awaitTermination().
- Retained factorial() method with simulated delay (Thread.sleep(1000)) to highlight concurrency.
- Printed execution time to compare efficiency with manual thread management.
WHY this change:
- Demonstrates how ExecutorService simplifies thread lifecycle management compared to raw threads.
- Improves readability and scalability—no need to manually handle Thread arrays or joins.
- Provides clear performance benefits by running factorials concurrently in a fixed-size pool.
- Serves as a foundation to contrast ExecutorService with other pooling strategies (single-thread, cached pool).
HINTS / NEXT STEPS:
- Experiment with Executors.newSingleThreadExecutor() to show sequential execution.
- Compare runtime between fixed thread pool vs manual threads.
- Extend example with Callable + Future to retrieve results instead of printing inline.
KEYWORDS:
java concurrency threadpool executors executorservice factorial multithreading.
Signed-off-by: https://github.com/Someshdiwan <[email protected]>1 parent 55c0dbc commit 356a3e4
File tree
1 file changed
+0
-63
lines changed- Section19MultiThreading/ThreadPooling/src/ExecutorsFramework
1 file changed
+0
-63
lines changedLines changed: 0 additions & 63 deletions
This file was deleted.
0 commit comments