A multi-threaded, console-based banking application that simulates core banking operations with a focus on thread safety and concurrency handling.
- Overview
- Features
- Architecture
- Project Structure
- Console UI Features
- Threading Model
- How to Run
- Sample Operations
- Handling Concurrency
- Error Handling
This application demonstrates a banking system that allows users to create accounts, deposit and withdraw funds, transfer money between accounts, and check balances - all in a thread-safe environment that handles concurrent operations properly.
- Account Management: Create bank accounts with unique account numbers
- Deposit & Withdrawal: Thread-safe deposit and withdrawal operations
- Fund Transfers: Transfer funds between accounts with proper synchronization
- Balance Inquiry: Check account balances securely
- Colorful UI: Enhanced console interface with colors and formatting
- Multi-threading: Execute operations concurrently using thread pool
- Proper Error Handling: Comprehensive exception management
The application follows a layered architecture pattern:
┌─────────────────┐
│ Presentation │ Controller layer handling user interaction
├─────────────────┤
│ Service │ Business logic implementation
├─────────────────┤
│ Repository │ Data access layer
├─────────────────┤
│ Model │ Domain objects
└─────────────────┘
BankApplication/
├── BankApp.java # Application entry point
├── controller/
│ └── BankController.java # Handles user interactions and menu
├── service/
│ ├── BankService.java # Banking service interface
│ └── BankServiceImpl.java # Banking service implementation
├── repository/
│ ├── AccountRepository.java # Account repository interface
│ └── InMemoryAccountRepository.java # In-memory implementation
├── model/
│ └── Account.java # Account entity with thread-safe operations
├── exception/
│ ├── AccountNotFoundException.java
│ └── InsufficientFundsException.java
└── util/
└── ConsoleUtils.java # Utility for enhanced console display
The application uses ConsoleUtils to provide an enhanced console experience:
- Color-coded Output: Different colors for different message types
- Formatted Headers: Styled headers for different sections
- Success/Error Indications: Visually distinguishable success and error messages
- Interactive Menus: Well-formatted menu options
- Progress Indicators: Visual feedback for operations
- Tabular Data: Data displayed in formatted tables
- Welcome Banner: Attractive welcome screen
The application uses a thread pool (ExecutorService) to handle concurrent operations:
- Core banking operations run in separate threads
- Synchronized blocks prevent race conditions during transfers
- Thread-safe collections store account data
- Atomic operations within the Account class
-
Compile all Java files:
javac -d bin d:\Java_Practice\System_Design_13\BankApplication\*.java -
Run the application:
java -cp bin BankApp -
Follow the on-screen menu to interact with the banking system
==== Create Account ====
Enter account number: 1001
✓ Account created successfully
==== Deposit Funds ====
Account number: 1001
Amount: 500
✓ Deposit successful
==== Check Balance ====
Account number: 1001
┌──────────────────┐
│ Balance: $500.0 │
└──────────────────┘
==== Transfer Funds ====
From Account: 1001
To Account: 1002
Amount: 200
✓ Transfer successful
The application handles concurrent access to accounts using:
- Synchronized Methods: Core Account methods are synchronized
- Lock Ordering: When transferring between accounts, locks are acquired in a consistent order
- Thread Pool: Operations are executed through a managed thread pool
- Thread-safe Collections: ConcurrentHashMap stores account data
The application handles various error conditions:
- Account Not Found: When operations reference non-existent accounts
- Insufficient Funds: When withdrawal/transfer amounts exceed balance
- Invalid Input: Validation for input parameters
- Visual Feedback: Color-coded error messages in the console UI