From 6845f42f7072b5b9f531229863ed94047da1aa0d Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Wed, 17 Jan 2024 14:12:34 +0100 Subject: [PATCH] Document virtual threads limitations This commit adds a new section in the Spring Boot reference documentation to mention potential throughput limitations with Java virtual threads support. This section links to the official Java documentation which expands much more on this matter. Closes gh-38883 --- .../src/docs/asciidoc/features/spring-application.adoc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/spring-application.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/spring-application.adoc index 3601cde03b..6618484a23 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/spring-application.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/spring-application.adoc @@ -384,6 +384,9 @@ Spring Boot can also be configured to expose a {spring-boot-actuator-restapi-doc === Virtual threads If you're running on Java 21 or up, you can enable virtual threads by setting the property configprop:spring.threads.virtual.enabled[] to `true`. +Before turning on this option for your application, you should consider https://docs.oracle.com/en/java/javase/21/core/virtual-threads.html[reading the official Java virtual threads documentation]. +In some cases, applications can experience lower throughput because of "Pinned Virtual Threads"; this page also explains how to detect such cases with JDK Flight Recorder or the `jcmd` CLI. + WARNING: One side effect of virtual threads is that these threads are daemon threads. A JVM will exit if there are no non-daemon threads. This behavior can be a problem when you rely on, e.g. `@Scheduled` beans to keep your application alive. @@ -391,3 +394,4 @@ If you use virtual threads, the scheduler thread is a virtual thread and therefo This does not only affect scheduling, but can be the case with other technologies, too! To keep the JVM running in all cases, it is recommended to set the property configprop:spring.main.keep-alive[] to `true`. This ensures that the JVM is kept alive, even if all threads are virtual threads. +