This project demonstrates Java 21 Virtual Threads with Quarkus to achieve better performance in I/O-intensive applications.
Virtual Threads (Project Loom) are lightweight threads that dramatically reduce the cost of blocking operations. Unlike traditional platform threads, virtual threads are managed by the JVM and can scale to millions of instances with minimal overhead.
Quarkus makes virtual threads simple to use with the @RunOnVirtualThread
annotation, automatically executing your REST endpoints on virtual threads for improved throughput in blocking scenarios.
This example shows a REST API managing application entities with PostgreSQL database operations, demonstrating how virtual threads improve performance under load.
For detailed information about Virtual Threads in Quarkus, see the official guide.
First, package the application and build the container image:
# Package the application
./mvnw package
# Build the container image
podman build -f src/main/docker/Dockerfile.jvm -t quay.io/rh-ee-amiralle/quarkus-applications:1.0 .
Start all services including the application container:
cd deployment
podman-compose up -d
This will start:
- PostgreSQL database
- Quarkus application container
- Prometheus (metrics)
- Grafana (dashboards)
- Jaeger (tracing)
- Grafana: http://localhost:3000 (dashboards and metrics)
- Prometheus: http://localhost:9090 (raw metrics)
- Jaeger: http://localhost:16686 (distributed tracing)
Load testing with JMeter demonstrates the benefits of virtual threads. The following captures show system performance under load:
Metric | Image |
---|---|
HTTP Endpoints | ![]() |
CPU Usage | ![]() |
JVM Memory | ![]() |
Thread Usage | ![]() |
JMeter Report | ![]() |
Virtual threads enable handling more concurrent requests with lower resource consumption compared to traditional platform threads.
- Virtual Threads: Complete guide to using Virtual Threads in Quarkus applications