How mohammadaamir1102/springbootvirtualthread works
Project type and purpose
• This is a standalone Spring Boot–based backend microservice whose purpose is to generate and serve CSV‐based reports (e.g. “simple_asia_report.csv”, “platform_asia_report.csv”, “virtual_asia_report.csv”) via REST endpoints.
• It demonstrates two threading models for report generation: standard platform threads vs. Java virtual threads (see ReportServiceByPlatformThread vs. ReportServiceByVirtualThread) and a custom Executor configuration (VTExecutorConfig).
File structure
• Top‐level files: Maven wrapper (mvnw, pom.xml), .gitignore, README.md.
• /reports folder: prepackaged CSV files used by the application.
• /src/main/java/com/aamir:
• config/VTExecutorConfig – defines Executor beans for platform or virtual threads.
• controller/ReportController – exposes REST endpoints.
• service/ReportService*, two implementations – business logic for report generation.
• repo/ConsumerRepo – DAO layer (likely a JPA repository).
• entity/ConsumerEntity – domain model.
• util/CsvReportUtil – file I/O helper for CSV parsing/writing.
• exception, constant, helper, response packages – error handling, message localization, API response wrappers.
• /src/main/resources/application.yml – runtime configuration.
• /src/test – unit tests for the Spring Boot application.
README
• The README contains only an illustrative image—no text. File tree and class names confirm this is a RESTful reporting service focusing on threading models.
a. Main components:
• External client (e.g. Postman, front-end, scheduler).
• Spring Boot application container:
– HTTP layer (ReportController)
– Service layer (ReportServiceByPlatformThread, ReportServiceByVirtualThread)
– Configuration (VTExecutorConfig)
– Utility (CsvReportUtil)
– Data layer (ConsumerRepo, ConsumerEntity + configured database)
– Exception handling (GlobalExceptionHandler, CustomException)
• File store (the /reports directory on the server’s filesystem)
• (Optionally) an external relational database (configured via application.yml).
b. Relationships and interactions:
1. Client issues HTTP GET (or POST) to ReportController.
2. Controller delegates to ReportService interface.
3. Depending on endpoint, Spring injects either the platform-thread or virtual-thread implementation.
4. Service uses VTExecutorConfig’s Executor to spawn tasks for reading/writing CSV (via CsvReportUtil) and/or fetching data from ConsumerRepo (database).
5. CsvReportUtil reads existing CSV files from /reports or writes new ones.
6. ConsumerRepo interacts with the database to fetch or persist ConsumerEntity records.
7. Service collects results, wraps them in ApiResponse, and returns to Controller.
8. Controller returns JSON or CSV stream to client.
c. Architectural patterns and design principles:
• Layered architecture (Controller → Service → Repository).
• Strategy pattern: two implementations of ReportService.
• Configuration‐injected Executor (Dependency Injection).
• Centralized exception handling (GlobalExceptionHandler).
• Utility class for low‐level I/O concerns (CsvReportUtil).
d. Relevant technologies and frameworks:
• Java 17+ with virtual threads (Project Loom).
• Spring Boot (Web, Data JPA).
• Maven build system.
• CSV file I/O (custom util).
Elements
• Cylindrical symbol for the database.