From 07a18c8ed8dd3e4732ccd5083c9f272953ff7068 Mon Sep 17 00:00:00 2001 From: Gennaro Rascato Date: Tue, 2 Sep 2025 08:40:15 +0200 Subject: [PATCH] Refine Task Javadoc about Runnable wrapping Clarify that the runnable associated with a Task may be wrapped by the framework (for scheduling or observability). The runnable returned by getRunnable() is the one to execute, and it may differ from the original instance supplied by the user. Closes #35394 Signed-off-by: Gennaro Rascato fix Signed-off-by: Gennaro Rascato --- .../org/springframework/scheduling/config/Task.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/spring-context/src/main/java/org/springframework/scheduling/config/Task.java b/spring-context/src/main/java/org/springframework/scheduling/config/Task.java index 04efa345808b..46db07ea7977 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/config/Task.java +++ b/spring-context/src/main/java/org/springframework/scheduling/config/Task.java @@ -26,6 +26,13 @@ * Holder class defining a {@code Runnable} to be executed as a task, typically at a * scheduled time or interval. See subclass hierarchy for various scheduling approaches. * + *

Note: this is not merely a holder for the user-provided + * {@code Runnable}. The framework may wrap the runnable instance for scheduling + * or observability purposes (for example with {@code OutcomeTrackingRunnable}, + * {@code SchedulingAwareRunnable}, or {@code SubscribingRunnable}). The runnable + * returned by {@link #getRunnable()} is the one to execute, and it may differ + * from the original object supplied by the user. + * * @author Chris Beams * @author Juergen Hoeller * @author Brian Clozel @@ -40,6 +47,8 @@ public class Task { /** * Create a new {@code Task}. + *

The provided runnable may be wrapped by the framework; see the class-level + * Javadoc for details. * @param runnable the underlying task to execute */ public Task(Runnable runnable) { @@ -51,6 +60,8 @@ public Task(Runnable runnable) { /** * Return the underlying task. + *

Note that this may be a framework wrapper around the original runnable + * supplied at construction time. */ public Runnable getRunnable() { return this.runnable;