Chapter 7. Modern Frameworks Utilizing Virtual Threads
The best way to predict the future is to invent it.
Alan Kay
With the introduction of virtual threads in JDK 21, the Java ecosystem has witnessed a significant shift in how frameworks handle concurrency. Many modern frameworks have embraced virtual threads to improve performance, scalability, and resource efficiency.
In this chapter, we will explore how leading frameworks, such as Spring Boot, Quarkus, and Jakarta EE, are integrating virtual threads. However, we will not go into the inner workings of these frameworks, as I assume those interested would prefer to explore each one in depth on their own.
Let’s begin.
Spring Boot
Spring Boot is one of the de facto frameworks for building enterprise applications in the Java ecosystem.
Historically, Spring Boot web applications have primarily followed a thread-per-request model, where a dedicated platform thread handles each incoming client request. While this approach works well under moderate loads, it encounters scalability challenges when dealing with a high volume of concurrent I/O-bound requests, as these requests are always served through platform threads.
To mitigate this, Spring Boot introduced asynchronous programming capabilities with annotations like @Async and abstractions such as TaskExecutor. However, this approach still relied on limited pools of platform threads, as shown in the following example:
@ConfigurationpublicclassThreadPoolConfig{@Beanpublic ...