https://github.com/brendanddev/custom-thread-pool
A Java implementation of a custom thread pool that demonstrates how task execution, worker management, and graceful shutdown work under the hood.
https://github.com/brendanddev/custom-thread-pool
thread-pool threads
Last synced: 8 months ago
JSON representation
A Java implementation of a custom thread pool that demonstrates how task execution, worker management, and graceful shutdown work under the hood.
- Host: GitHub
- URL: https://github.com/brendanddev/custom-thread-pool
- Owner: brendanddev
- License: mit
- Created: 2025-09-30T12:39:07.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-10-07T17:17:57.000Z (8 months ago)
- Last Synced: 2025-10-07T17:25:04.122Z (8 months ago)
- Topics: thread-pool, threads
- Language: Java
- Homepage:
- Size: 52.7 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Custom Thread Pool
A custom thread pool implementation in Java, built from scratch to explore and understand the **internal workings of thread pools**. This project focuses on implementing the core mechanisms manually, rather than relying on Java’s built-in concurrency utilities.
---
## Features
- **Custom TaskQueue** – A thread-safe FIFO queue implemented from scratch using `synchronized`, `wait()`, and `notifyAll()`.
- **WorkerThread Management** – Multiple worker threads continuously dequeue and execute tasks.
- **Graceful Shutdown** – Supports a clean shutdown where queued tasks are completed using the **poison pill pattern**.
- **Immediate Shutdown** – Can stop all active tasks and return unexecuted tasks immediately.
- **Exception Handling** – Worker threads catch exceptions from tasks to prevent thread death.
---
### References & Inspiration
- [Java Concurrency Tutorial](https://docs.oracle.com/javase/tutorial/essential/concurrency/)
- [Baeldung: Building Thread Pools](https://www.baeldung.com/thread-pool-java-and-guava)
- [Poison Pill Pattern](https://java-design-patterns.com/patterns/poison-pill/)
- [Thread Pool Policies](https://medium.com/@ankithahjpgowda/policies-of-threadpoolexecutor-in-java-75f22fd6f637)
- [ava Thread Pool Execution and Rejection Policies](https://medium.com/@umeshcapg/understanding-java-thread-pool-execution-and-rejection-policies-b97eeb58094a)