This project is a concurrency exercise inspired by flight booking systems of digital airline companies. It demonstrates domain-driven design principles and concurrency control in a rich domain model.
- Core entity for flight bookings
- Maintains seats and their booking status
- Ensures thread safety with ReentrantLock
- Enforces invariants:
- Cannot book more than capacity
- A seat can only be booked once
- Represents a passenger's booking for a specific seat
- Immutable after creation
- Links passenger, flight, and seat number
- Represents a customer who can book flights
- Contains identification and contact information
- Uniquely identifies a flight with format "EDR" followed by 5 digits
- Immutable value object
- Identifies a specific seat on a flight
- Format: row number (1-99) followed by seat letter (A-F)
- DTO for carrying booking request data
- Contains passenger information and desired flight
- Orchestrates flight bookings across multiple flights
- Provides sequential and parallel booking strategies:
- Sequential processing
- Parallel processing with fixed thread pool
- Parallel processing with virtual threads (Java 21 feature)
- Tracks booking results and performance metrics
The project demonstrates several concurrency techniques:
- Thread-safe entity design using ReentrantLock in the Flight entity
- Use of ConcurrentHashMap for thread-safe collections
- Java 21 Virtual Threads implementation
- Traditional ExecutorService with fixed thread pool
- Atomic operations and concurrent collections
- Java 21
- Maven
mvn clean package
mvn test
The project includes performance tests comparing:
- Sequential booking
- Fixed thread pool booking
- Virtual thread booking
The ConcurrencyStressTest class demonstrates massive concurrent bookings with 10,000+ virtual threads.
- Encapsulation of concurrency inside domain objects
- Ensuring domain invariants under high concurrency
- Virtual Threads vs. platform threads performance comparison
- Thread-safe collections and their proper usage
- Designing immutable value objects
src/main/java/com/edreams/booking/domain- Domain model classessrc/main/java/com/edreams/booking/service- Service layersrc/test/java/com/edreams/booking/domain- Unit tests for domain modelsrc/test/java/com/edreams/booking/service- Service tests including stress tests