Skip to content

Commit 39b551c

Browse files
committed
Document hand-off to execution thread (including ScheduledFuture impact)
Closes gh-32589
1 parent 23696b7 commit 39b551c

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

Diff for: spring-context/src/main/java/org/springframework/scheduling/TaskScheduler.java

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -68,7 +68,7 @@ default Clock getClock() {
6868
* @param trigger an implementation of the {@link Trigger} interface,
6969
* e.g. a {@link org.springframework.scheduling.support.CronTrigger} object
7070
* wrapping a cron expression
71-
* @return a {@link ScheduledFuture} representing pending completion of the task,
71+
* @return a {@link ScheduledFuture} representing pending execution of the task,
7272
* or {@code null} if the given Trigger object never fires (i.e. returns
7373
* {@code null} from {@link Trigger#nextExecution})
7474
* @throws org.springframework.core.task.TaskRejectedException if the given task was not accepted
@@ -85,7 +85,7 @@ default Clock getClock() {
8585
* @param task the Runnable to execute whenever the trigger fires
8686
* @param startTime the desired execution time for the task
8787
* (if this is in the past, the task will be executed immediately, i.e. as soon as possible)
88-
* @return a {@link ScheduledFuture} representing pending completion of the task
88+
* @return a {@link ScheduledFuture} representing pending execution of the task
8989
* @throws org.springframework.core.task.TaskRejectedException if the given task was not accepted
9090
* for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress)
9191
* @since 5.0
@@ -99,7 +99,7 @@ default Clock getClock() {
9999
* @param task the Runnable to execute whenever the trigger fires
100100
* @param startTime the desired execution time for the task
101101
* (if this is in the past, the task will be executed immediately, i.e. as soon as possible)
102-
* @return a {@link ScheduledFuture} representing pending completion of the task
102+
* @return a {@link ScheduledFuture} representing pending execution of the task
103103
* @throws org.springframework.core.task.TaskRejectedException if the given task was not accepted
104104
* for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress)
105105
* @deprecated as of 6.0, in favor of {@link #schedule(Runnable, Instant)}
@@ -118,7 +118,7 @@ default ScheduledFuture<?> schedule(Runnable task, Date startTime) {
118118
* @param startTime the desired first execution time for the task
119119
* (if this is in the past, the task will be executed immediately, i.e. as soon as possible)
120120
* @param period the interval between successive executions of the task
121-
* @return a {@link ScheduledFuture} representing pending completion of the task
121+
* @return a {@link ScheduledFuture} representing pending execution of the task
122122
* @throws org.springframework.core.task.TaskRejectedException if the given task was not accepted
123123
* for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress)
124124
* @since 5.0
@@ -134,7 +134,7 @@ default ScheduledFuture<?> schedule(Runnable task, Date startTime) {
134134
* @param startTime the desired first execution time for the task
135135
* (if this is in the past, the task will be executed immediately, i.e. as soon as possible)
136136
* @param period the interval between successive executions of the task (in milliseconds)
137-
* @return a {@link ScheduledFuture} representing pending completion of the task
137+
* @return a {@link ScheduledFuture} representing pending execution of the task
138138
* @throws org.springframework.core.task.TaskRejectedException if the given task was not accepted
139139
* for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress)
140140
* @deprecated as of 6.0, in favor of {@link #scheduleAtFixedRate(Runnable, Instant, Duration)}
@@ -151,7 +151,7 @@ default ScheduledFuture<?> scheduleAtFixedRate(Runnable task, Date startTime, lo
151151
* {@link ScheduledFuture} gets cancelled.
152152
* @param task the Runnable to execute whenever the trigger fires
153153
* @param period the interval between successive executions of the task
154-
* @return a {@link ScheduledFuture} representing pending completion of the task
154+
* @return a {@link ScheduledFuture} representing pending execution of the task
155155
* @throws org.springframework.core.task.TaskRejectedException if the given task was not accepted
156156
* for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress)
157157
* @since 5.0
@@ -165,7 +165,7 @@ default ScheduledFuture<?> scheduleAtFixedRate(Runnable task, Date startTime, lo
165165
* {@link ScheduledFuture} gets cancelled.
166166
* @param task the Runnable to execute whenever the trigger fires
167167
* @param period the interval between successive executions of the task (in milliseconds)
168-
* @return a {@link ScheduledFuture} representing pending completion of the task
168+
* @return a {@link ScheduledFuture} representing pending execution of the task
169169
* @throws org.springframework.core.task.TaskRejectedException if the given task was not accepted
170170
* for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress)
171171
* @deprecated as of 6.0, in favor of {@link #scheduleAtFixedRate(Runnable, Duration)}
@@ -185,7 +185,7 @@ default ScheduledFuture<?> scheduleAtFixedRate(Runnable task, long period) {
185185
* @param startTime the desired first execution time for the task
186186
* (if this is in the past, the task will be executed immediately, i.e. as soon as possible)
187187
* @param delay the delay between the completion of one execution and the start of the next
188-
* @return a {@link ScheduledFuture} representing pending completion of the task
188+
* @return a {@link ScheduledFuture} representing pending execution of the task
189189
* @throws org.springframework.core.task.TaskRejectedException if the given task was not accepted
190190
* for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress)
191191
* @since 5.0
@@ -203,7 +203,7 @@ default ScheduledFuture<?> scheduleAtFixedRate(Runnable task, long period) {
203203
* (if this is in the past, the task will be executed immediately, i.e. as soon as possible)
204204
* @param delay the delay between the completion of one execution and the start of the next
205205
* (in milliseconds)
206-
* @return a {@link ScheduledFuture} representing pending completion of the task
206+
* @return a {@link ScheduledFuture} representing pending execution of the task
207207
* @throws org.springframework.core.task.TaskRejectedException if the given task was not accepted
208208
* for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress)
209209
* @deprecated as of 6.0, in favor of {@link #scheduleWithFixedDelay(Runnable, Instant, Duration)}
@@ -220,7 +220,7 @@ default ScheduledFuture<?> scheduleWithFixedDelay(Runnable task, Date startTime,
220220
* {@link ScheduledFuture} gets cancelled.
221221
* @param task the Runnable to execute whenever the trigger fires
222222
* @param delay the delay between the completion of one execution and the start of the next
223-
* @return a {@link ScheduledFuture} representing pending completion of the task
223+
* @return a {@link ScheduledFuture} representing pending execution of the task
224224
* @throws org.springframework.core.task.TaskRejectedException if the given task was not accepted
225225
* for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress)
226226
* @since 5.0
@@ -235,7 +235,7 @@ default ScheduledFuture<?> scheduleWithFixedDelay(Runnable task, Date startTime,
235235
* @param task the Runnable to execute whenever the trigger fires
236236
* @param delay the delay between the completion of one execution and the start of the next
237237
* (in milliseconds)
238-
* @return a {@link ScheduledFuture} representing pending completion of the task
238+
* @return a {@link ScheduledFuture} representing pending execution of the task
239239
* @throws org.springframework.core.task.TaskRejectedException if the given task was not accepted
240240
* for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress)
241241
* @deprecated as of 6.0, in favor of {@link #scheduleWithFixedDelay(Runnable, Duration)}

Diff for: spring-context/src/main/java/org/springframework/scheduling/concurrent/SimpleAsyncTaskScheduler.java

+6
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@
7474
* which tend to have specific constraints for the scheduler thread pool,
7575
* requiring a separate thread pool for general executor purposes in practice.
7676
*
77+
* <p><b>NOTE: This scheduler variant does not track the actual completion of tasks
78+
* but rather just the hand-off to an execution thread.</b> As a consequence,
79+
* a {@link ScheduledFuture} handle (e.g. from {@link #schedule(Runnable, Instant)})
80+
* represents that hand-off rather than the actual completion of the provided task
81+
* (or series of repeated tasks).
82+
*
7783
* <p>As an alternative to the built-in thread-per-task capability, this scheduler
7884
* can also be configured with a separate target executor for scheduled task
7985
* execution through {@link #setTargetTaskExecutor}: e.g. pointing to a shared

Diff for: spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskScheduler.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,14 @@
4848
/**
4949
* A standard implementation of Spring's {@link TaskScheduler} interface, wrapping
5050
* a native {@link java.util.concurrent.ScheduledThreadPoolExecutor} and providing
51-
* all applicable configuration options for it.
51+
* all applicable configuration options for it. The default number of scheduler
52+
* threads is 1; a higher number can be configured through {@link #setPoolSize}.
53+
*
54+
* <p>This is Spring's traditional scheduler variant, staying as close as possible to
55+
* {@link java.util.concurrent.ScheduledExecutorService} semantics. Task execution happens
56+
* on the scheduler thread(s) rather than on separate execution threads. As a consequence,
57+
* a {@link ScheduledFuture} handle (e.g. from {@link #schedule(Runnable, Instant)})
58+
* represents the actual completion of the provided task (or series of repeated tasks).
5259
*
5360
* @author Juergen Hoeller
5461
* @author Mark Fisher
@@ -59,6 +66,8 @@
5966
* @see #setExecuteExistingDelayedTasksAfterShutdownPolicy
6067
* @see #setThreadFactory
6168
* @see #setErrorHandler
69+
* @see ThreadPoolTaskExecutor
70+
* @see SimpleAsyncTaskScheduler
6271
*/
6372
@SuppressWarnings({"serial", "deprecation"})
6473
public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport

0 commit comments

Comments
 (0)