Jetty 12 – Virtual Threads Support
Jetty 12 introduces support for Virtual Threads, a feature that was first introduced in Java 19. This support has been available in Jetty since version 10.0.12 and Jetty 11.0.12. When enabled, applications in Jetty are invoked using a virtual thread, which combines the simplicity of blocking APIs with the scalability benefits of virtual threads.
Historically, developers have relied on blocking APIs based on InputStream and OutputStream or JDBC. While these APIs are easy to use, they come with a cost. When a thread blocks, all the resources associated with that thread are retained, limiting the scalability of the server.
To address this, non-blocking asynchronous and reactive APIs were introduced. However, REST APIs like JAX-RS or Jakarta RESTful Web Services have not fully adopted these APIs, resulting in scalability issues for web applications.
Virtual threads aim to bridge this gap by providing simple-to-use blocking APIs with the scalability of non-blocking APIs. With Jetty 12, developers can leverage the benefits of virtual threads to achieve improved performance and reduced resource usage.
To demonstrate the power of virtual threads, consider the case of a web application that switched from blocking APIs to non-blocking APIs. The number of threads used by the application decreased from over 1000 to just 10. This significant reduction in thread usage highlights the scalability advantages of virtual threads.
In terms of architecture, Jetty 12 utilizes an AdaptiveExecutionStrategy, which determines how to efficiently handle requests based on the workload. This architecture ensures that Jetty remains non-blocking and can handle high loads without sacrificing performance.
Overall, Jetty 12's support for virtual threads is a significant development for developers looking to improve the scalability of their web applications. By combining the simplicity of blocking APIs with the scalability benefits of virtual threads, Jetty 12 empowers developers to build high-performance applications with reduced resource usage.
To get started with Jetty 12 and virtual threads, developers can refer to the official documentation and examples provided by the Jetty project. The documentation includes instructions for both embedded and standalone usage, enabling developers to seamlessly integrate virtual threads into their applications.
With Jetty 12's virtual threads support, developers can stay ahead of the curve and leverage the latest advancements in Java to build scalable and efficient web applications.