A simplified but realistic concurrent banking system simulator written in Java.
The project demonstrates proper multithreading design, deadlock-free transfers, fine-grained locking, and invariant verification using JUnit 5.
This repository is ideal for learning:
- Thread safety and correctness in Java
- Lock ordering strategies to prevent deadlock
- Designing atomic operations (like money transfers)
- Using ExecutorService for parallel workloads
- Writing concurrency stress tests and verifying invariants
Each account uses its own ReentrantLock for fine-grained synchronization.
Transfers between accounts are executed using a thread pool and Callable tasks.
Account locks are always acquired in consistent sorted order to avoid circular wait.
The simulator guarantees:
- Total system balance remains constant
- No account ever goes negative
A stress test launches thousands of randomized transfers across multiple threads and verifies all invariants at the end.
java -cp target/bank-simulator-1.0-SNAPSHOT.jar com.example.bank.Main