From 490161c0ed70be72f4020a2a30ef9be73ef221e1 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Fri, 23 Feb 2024 09:39:15 +0000 Subject: [PATCH] Polish warning about virtual threads and the JVM exiting Closes gh-39732 --- .../src/docs/asciidoc/features/spring-application.adoc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) 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 6618484a237..feef5066595 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 @@ -387,11 +387,10 @@ If you're running on Java 21 or up, you can enable virtual threads by setting th 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. +WARNING: One side effect of virtual threads is that they are daemon threads. +A JVM will exit if all of its threads are daemon threads. +This behavior can be a problem when you rely on `@Scheduled` beans, for example, to keep your application alive. If you use virtual threads, the scheduler thread is a virtual thread and therefore a daemon thread and won't keep the JVM alive. -This does not only affect scheduling, but can be the case with other technologies, too! +This not only affects scheduling and 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. -