Skip to content

Commit 6845f42

Browse files
committed
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
1 parent aec4550 commit 6845f42

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/spring-application.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,10 +384,14 @@ Spring Boot can also be configured to expose a {spring-boot-actuator-restapi-doc
384384
=== Virtual threads
385385
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`.
386386

387+
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].
388+
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.
389+
387390
WARNING: One side effect of virtual threads is that these threads are daemon threads.
388391
A JVM will exit if there are no non-daemon threads.
389392
This behavior can be a problem when you rely on, e.g. `@Scheduled` beans to keep your application alive.
390393
If you use virtual threads, the scheduler thread is a virtual thread and therefore a daemon thread and won't keep the JVM alive.
391394
This does not only affect scheduling, but can be the case with other technologies, too!
392395
To keep the JVM running in all cases, it is recommended to set the property configprop:spring.main.keep-alive[] to `true`.
393396
This ensures that the JVM is kept alive, even if all threads are virtual threads.
397+

0 commit comments

Comments
 (0)