Skip to content

Java use Virtual Threads Java 25+ #465

@maheshkumarbh

Description

@maheshkumarbh

Improve Concurrency Model Using Virtual Threads in Spring Boot (JDK 25+)


Description

We should consider improving our current concurrency model by adopting Virtual Threads in Spring Boot as an alternative to the existing CompletableFuture-based asynchronous approach.

This change aims to simplify code while maintaining high performance, especially for I/O-bound workloads. It also integrates well with observability tools, making debugging and monitoring easier.

⚠️ This approach requires JDK 25 or later to ensure full support and stability of Virtual Threads and related enhancements.


Current Approach

  • Uses CompletableFuture for asynchronous, non-blocking execution

  • Requires functional-style programming (chaining, callbacks)

  • Leads to increased code complexity and harder debugging


Proposed Approach

  • Use Virtual Threads (Project Loom) in Spring Boot

  • Follow a thread-per-task (blocking style) model

  • Keep code simple and imperative while still achieving high throughput


Comparison

Aspect Virtual Threads CompletableFuture
Concurrency Model Thread-per-task (blocking) Async (non-blocking)
Code Complexity Low (simple, imperative) High (chaining/callbacks)
Throughput (I/O bound) Very High Very High
Memory Usage Very Low (~1–2 KB/thread) Low
Debugging Easy (standard stack traces) Hard (complex call stacks)

Benefits

  • Simpler and more readable code

  • Easier debugging with standard stack traces

  • Comparable or better performance for I/O-heavy workloads

  • Better compatibility with observability tooling


Additional Consideration

As a next step in Java evolution, we should also explore GraalVM for improved startup time and runtime performance:
https://www.graalvm.org/


Acceptance Criteria

  • Upgrade runtime to JDK 25+

  • Evaluate Virtual Threads integration in current services

  • Benchmark performance vs existing CompletableFuture implementation

  • Validate observability (logging, tracing, metrics) compatibility

  • Document migration approach and best practices


enhancement performance java

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions