Skip to content

Commit 5ee5225

Browse files
committed
Explain that enabling virtual threads disables traditional thread pools
Closes gh-41937
1 parent 67cf325 commit 5ee5225

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/task/TaskExecutionProperties.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,30 +83,32 @@ public static class Pool {
8383

8484
/**
8585
* Queue capacity. An unbounded capacity does not increase the pool and therefore
86-
* ignores the "max-size" property.
86+
* ignores the "max-size" property. Doesn't have an effect if virtual threads are
87+
* enabled.
8788
*/
8889
private int queueCapacity = Integer.MAX_VALUE;
8990

9091
/**
91-
* Core number of threads.
92+
* Core number of threads. Doesn't have an effect if virtual threads are enabled.
9293
*/
9394
private int coreSize = 8;
9495

9596
/**
9697
* Maximum allowed number of threads. If tasks are filling up the queue, the pool
9798
* can expand up to that size to accommodate the load. Ignored if the queue is
98-
* unbounded.
99+
* unbounded. Doesn't have an effect if virtual threads are enabled.
99100
*/
100101
private int maxSize = Integer.MAX_VALUE;
101102

102103
/**
103104
* Whether core threads are allowed to time out. This enables dynamic growing and
104-
* shrinking of the pool.
105+
* shrinking of the pool. Doesn't have an effect if virtual threads are enabled.
105106
*/
106107
private boolean allowCoreThreadTimeout = true;
107108

108109
/**
109-
* Time limit for which threads may remain idle before being terminated.
110+
* Time limit for which threads may remain idle before being terminated. Doesn't
111+
* have an effect if virtual threads are enabled.
110112
*/
111113
private Duration keepAlive = Duration.ofSeconds(60);
112114

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/task/TaskSchedulingProperties.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ public void setThreadNamePrefix(String threadNamePrefix) {
6363
public static class Pool {
6464

6565
/**
66-
* Maximum allowed number of threads.
66+
* Maximum allowed number of threads. Doesn't have an effect if virtual threads
67+
* are enabled.
6768
*/
6869
private int size = 1;
6970

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -897,12 +897,14 @@ public void setBuffered(boolean buffered) {
897897
public static class Threads {
898898

899899
/**
900-
* Maximum amount of worker threads.
900+
* Maximum amount of worker threads. Doesn't have an effect if virtual threads
901+
* are enabled.
901902
*/
902903
private int max = 200;
903904

904905
/**
905-
* Minimum amount of worker threads.
906+
* Minimum amount of worker threads. Doesn't have an effect if virtual threads
907+
* are enabled.
906908
*/
907909
private int minSpare = 10;
908910

@@ -1309,12 +1311,14 @@ public static class Threads {
13091311
private Integer selectors = -1;
13101312

13111313
/**
1312-
* Maximum number of threads.
1314+
* Maximum number of threads. Doesn't have an effect if virtual threads are
1315+
* enabled.
13131316
*/
13141317
private Integer max = 200;
13151318

13161319
/**
1317-
* Minimum number of threads.
1320+
* Minimum number of threads. Doesn't have an effect if virtual threads are
1321+
* enabled.
13181322
*/
13191323
private Integer min = 8;
13201324

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,9 @@ If you're running on Java 21 or up, you can enable virtual threads by setting th
387387
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].
388388
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.
389389

390+
NOTE: If virtual threads are enabled, properties which configure thread pools don't have an effect anymore.
391+
That's because virtual threads are scheduled on a JVM wide platform thread pool and not on dedicated thread pools.
392+
390393
WARNING: One side effect of virtual threads is that they are daemon threads.
391394
A JVM will exit if all of its threads are daemon threads.
392395
This behavior can be a problem when you rely on `@Scheduled` beans, for example, to keep your application alive.

0 commit comments

Comments
 (0)