This project demonstrates advanced multithreading concepts in Java, including thread synchronization, parallel execution, asynchronous computation, and coordination between threads — all combined in a single example.
✅ ExecutorService – Efficient thread pool management
✅ Callable & Future – Parallel computation with return values
✅ ReentrantLock – Thread-safe shared resource access
✅ CountDownLatch – Coordinating multiple threads
✅ CompletableFuture – Asynchronous, non-blocking computation
✅ Graceful shutdown – Proper thread pool termination
| Concept | Description |
|---|---|
| ExecutorService | Manages a pool of worker threads instead of creating new threads manually. |
| Callable & Future | Allows threads to return results and handle exceptions. |
| ReentrantLock | Provides explicit locking for shared resource protection. |
| CountDownLatch | Helps coordinate multiple threads to wait for each other’s completion. |
| CompletableFuture | Enables async programming with chained callbacks. |
| Graceful Shutdown | Ensures no running tasks are abruptly terminated. |
A thread-safe class that handles deposit and withdrawal operations using a ReentrantLock to prevent race conditions.
- Submits multiple Callable tasks using an ExecutorService.
- Uses a CountDownLatch to synchronize threads.
- Performs an asynchronous interest calculation with CompletableFuture.
- Demonstrates Future usage for retrieving computed values.
pool-1-thread-1 deposited 200.0 | Balance: 1200.0
pool-1-thread-2 withdrew 100.0 | Balance: 1100.0
pool-1-thread-3 deposited 300.0 | Balance: 1400.0
pool-1-thread-4 withdrew 500.0 | Balance: 900.0
All basic transactions completed.
Calculating interest asynchronously...
Interest calculated: 45.0
main deposited 45.0 | Balance: 945.0
Final balance after interest: 945.0
Executor shutdown gracefully.
- Multithreading fundamentals
- Concurrency utilities (
java.util.concurrent) - Thread safety and synchronization
- Modern async programming in Java