You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Auto-configure SimpleAsyncTaskScheduler when virtual threads are enabled
This auto-configures a new SimpleAsyncTaskSchedulerBuilder bean in the
context. This bean is configured to use virtual threads, if enabled.
SimpleAsyncTaskSchedulerCustomizers can be used to customize the built
SimpleAsyncTaskScheduler.
If virtual threads are enabled, the application task scheduler is
configured to be a SimpleAsyncTaskScheduler.
Adds a new configuration property spring.task.scheduling.simple
.concurrency-limit
Closesgh-36609
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/task/TaskSchedulingAutoConfiguration.java
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/task/TaskSchedulingConfigurations.java
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/task/TaskSchedulingProperties.java
+25-1
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
/*
2
-
* Copyright 2012-2019 the original author or authors.
2
+
* Copyright 2012-2023 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -31,6 +31,8 @@ public class TaskSchedulingProperties {
31
31
32
32
privatefinalPoolpool = newPool();
33
33
34
+
privatefinalSimplesimple = newSimple();
35
+
34
36
privatefinalShutdownshutdown = newShutdown();
35
37
36
38
/**
@@ -42,6 +44,10 @@ public Pool getPool() {
42
44
returnthis.pool;
43
45
}
44
46
47
+
publicSimplegetSimple() {
48
+
returnthis.simple;
49
+
}
50
+
45
51
publicShutdowngetShutdown() {
46
52
returnthis.shutdown;
47
53
}
@@ -71,6 +77,24 @@ public void setSize(int size) {
71
77
72
78
}
73
79
80
+
publicstaticclassSimple {
81
+
82
+
/**
83
+
* Set the maximum number of parallel accesses allowed. -1 indicates no
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/task/TaskSchedulingAutoConfigurationTests.java
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/task-execution-and-scheduling.adoc
+7-4
Original file line number
Diff line number
Diff line change
@@ -36,8 +36,11 @@ Those default settings can be fine-tuned using the `spring.task.execution` names
36
36
This changes the thread pool to use a bounded queue so that when the queue is full (100 tasks), the thread pool increases to maximum 16 threads.
37
37
Shrinking of the pool is more aggressive as threads are reclaimed when they are idle for 10 seconds (rather than 60 seconds by default).
38
38
39
-
A `ThreadPoolTaskScheduler` can also be auto-configured if need to be associated to scheduled task execution (using `@EnableScheduling` for instance).
40
-
The thread pool uses one thread by default and its settings can be fine-tuned using the `spring.task.scheduling` namespace, as shown in the following example:
39
+
A scheduler can also be auto-configured if need to be associated to scheduled task execution (using `@EnableScheduling` for instance).
40
+
When virtual threads are enabled (using Java 21+ and configprop:spring.threads.virtual.enabled[] set to `true`) this will be a `SimpleAsyncTaskScheduler` that uses virtual threads.
41
+
Otherwise, it will be a `ThreadPoolTaskScheduler` with sensible defaults.
42
+
43
+
The `ThreadPoolTaskScheduler` uses one thread by default and its settings can be fine-tuned using the `spring.task.scheduling` namespace, as shown in the following example:
@@ -49,5 +52,5 @@ The thread pool uses one thread by default and its settings can be fine-tuned us
49
52
size: 2
50
53
----
51
54
52
-
A `ThreadPoolTaskExecutorBuilder` bean, a `SimpleAsyncTaskExecutorBuilder` bean and a `ThreadPoolTaskSchedulerBuilder` bean are made available in the context if a custom executor or scheduler needs to be created.
53
-
The `SimpleAsyncTaskExecutorBuilder` is auto-configured to use virtual threads if they are enabled (using Java 21+ and configprop:spring.threads.virtual.enabled[] set to `true`).
55
+
A `ThreadPoolTaskExecutorBuilder` bean, a `SimpleAsyncTaskExecutorBuilder` bean, a `ThreadPoolTaskSchedulerBuilder` bean and a `SimpleAsyncTaskSchedulerBuilder` are made available in the context if a custom executor or scheduler needs to be created.
56
+
The `SimpleAsyncTaskExecutorBuilder` and `SimpleAsyncTaskSchedulerBuilder` beans are auto-configured to use virtual threads if they are enabled (using Java 21+ and configprop:spring.threads.virtual.enabled[] set to `true`).
0 commit comments