A multithreaded Java simulation that models fund transfers between two bank accounts using ExecutorService. The system ensures thread safety and prevents race conditions using synchronized methods.
BankingSystemSimulation/ βββ pom.xml βββ src/ βββ main/ βββ java/ βββ com/ βββ ritesh/ βββ banking/ βββ Account.java βββ UserTransaction.java βββ Main.java
---
### βοΈ Technologies Used
* Java 17+ (or any compatible version)
* Maven (build & dependency management)
* IntelliJ IDEA (recommended IDE)
* Java `ExecutorService` for multithreading
---
### π How It Works
* Two accounts: **Ritesh** (rich π°) and **Amit** (not so much π
)
* A thread pool executes randomized transfer tasks between them.
* Transfers are thread-safe using `synchronized` methods.
* Balance checks ensure transfers donβt proceed if funds are insufficient.
---
### β
Features
* π Concurrent money transfers using multiple threads
* πΈ Synchronized deposit, withdraw, and transfer logic
* π« Prevents overdrawing with balance checks
* π§ Demonstrates basic concurrency and thread-safe operations in Java
---
### βΆοΈ Run the Simulation
#### Step 1: Clone or download the repo
```bash
git clone https://github.com/your-username/BankingSystemSimulation.git
- Make sure the entire project folder is opened (not just
/src) - Let Maven finish indexing
You should see output like:
pool-1-thread-2 withdrew $2000 from Ritesh. New Balance is $9998000
pool-1-thread-2 deposited $2000 to Amit. New Balance is $3000
pool-1-thread-2 transferred $2000 β from Ritesh to Amit
pool-1-thread-3 not enough balance in Amit. Balance is $1000
pool-1-thread-1 transferred $2000 β from Ritesh to Amit
pool-1-thread-4 transferred $2000 β from Amit to Ritesh
- Add more accounts (dynamic)
- Log transactions to a file
- Add transaction timestamps or IDs
- Simulate deadlocks and how to prevent them
- Swing/JavaFX UI for live visualization
Ritesh Backend Developer
MIT License β feel free to use and modify!