Spring Boot 3.2 Delivers Support for Virtual Threads and Modern RestClient and JdbcClient

MMS Founder
MMS Sirisha Pratha

Article originally posted on InfoQ. Visit InfoQ

The Spring Boot team released Spring Boot 3.2 in November 2023. This latest release is packed with features, the most noteworthy of which is the support for virtual threads and Coordinated Restore at Checkpoint (CRaC). Other features include SSL-bundle reloading, support for the RestClient and JdbcClient interfaces, and observability improvements.

In JDK 21, a particularly significant feature is Project Loom’s virtual threads, which the JEP describes as lightweight threads that dramatically reduce the effort of writing, maintaining, and observing high-throughput concurrent applications.

Spring Boot 3.2 has integrated support for the virtual threads feature. To use it, set the property spring.threads.virtual.enabled to true and use JDK 21. Under the hood, Tomcat and Jetty will use virtual threads, which means the application code processing the web requests will now operate on virtual threads.

Furthermore, when virtual threads are enabled via the property, the SimpleAsyncTaskExecutor class is configured to use virtual threads, which directly affects the behavior of methods annotated with @EnableAsync, asynchronous Spring’s MVC requests, and Spring WebFlux blocking execution calls, as they will all now create virtual threads instead of platform threads.

Other areas impacted by this feature are RabbitMQ and Kafka Listeners, Spring Data Redis and Spring for Apache Pulsar.

RestClient, a modern alternative to RestTemplate, is a synchronous HTTP client introduced in Spring Framework 6.1. Spring Boot will now create and pre-configure bean RestClient.Builder to create RestClient instances. It offers a functional style API like its counterpart, WebClient, in Spring WebFlux. One main advantage of using RestClient is that there is no need to add the additional dependency on Spring WebFlux to call remote REST APIs.

The Spring team recommends using RestClient to call remote REST services unless Spring WebFlux or Project Reactor is in use, in which case WebClient is the suggested choice.

Similar to the RestClient, a new interface, JdbcClient, was introduced in Spring Framework 6.1 and is auto-configured in Spring Boot 3.2. It offers a fluent API to perform common database operations.

SSL Bundles were first introduced in Spring Boot 3.1 to configure and consume SSL information such as keystores, certificates, private keys, etc. In Spring Boot 3.2, it is possible to reload SSL bundles when the SSL trust material changes by setting the property reload-on-update=true. Hot reloading is supported for Netty and Tomcat web servers. A related property spring.ssl.bundle.watch.file.quiet-period=10s is available to configure a quiet period, after which the changes are detected.

Several observability improvements made it to Spring Boot 3.2. Micrometer’s annotations, such as @Timed, @Counted, @NewSpan, @ContinueSpan and @Observed, are available to use declaratively when spring-boot-starter-aop is on the classpath. Methods annotated with @Scheduled are instrumented for observability. It is possible to disable observations starting with the specified name by setting the property management.observations.enable to false. The property management.metrics.tags is deprecated in Spring Boot 3.2 and is replaced with management.observations.key-values. Add common key-values that can be applied to all observations with this property. Read the full list of observability improvements in this release.

Spring Developer Advocate at Broadcom Josh Long told InfoQ:

There has never been a better time to be a Spring and Java developer. Spring Boot 3.2 delivers huge runtime efficiencies with Project CRaC support (available in certain distributions of OpenJDK) and Project Loom, available as of Java 21. These features, combined with existing work supporting GraalVM native images, offer amazing opportunities for Spring Boot developers looking for the best experience in production.

See official release notes for a complete list of upgrades and noteworthy changes.

About the Author

Subscribe for MMS Newsletter

By signing up, you will receive updates about our latest information.

  • This field is for validation purposes and should be left unchanged.