diff --git a/org.springframework.context/src/main/java/org/springframework/scheduling/annotation/EnableScheduling.java b/org.springframework.context/src/main/java/org/springframework/scheduling/annotation/EnableScheduling.java index 7dc3ef9be5a..66a042c38b8 100644 --- a/org.springframework.context/src/main/java/org/springframework/scheduling/annotation/EnableScheduling.java +++ b/org.springframework.context/src/main/java/org/springframework/scheduling/annotation/EnableScheduling.java @@ -122,26 +122,43 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar; * public class AppConfig implements SchedulingConfigurer { * @Override * public void configureTasks(ScheduledTaskRegistrar taskRegistrar) { - * taskRegistrar.setScheduler(taskExecutor()); + * taskRegistrar.setScheduler(taskScheduler()); * taskRegistrar.addTriggerTask( * new Runnable() { - * task().work(); + * myTask().work(); * }, * new CustomTrigger() * ); * } * * @Bean - * public Executor taskExecutor() { - * return Executors.newScheduledThreadPool(100); + * public Executor taskScheduler() { + * return Executors.newScheduledThreadPool(42); * } * * @Bean - * public MyTask task() { + * public MyTask myTask() { * return new MyTask(); * } * } * + *
For reference, the example above can be compared to the following Spring XML + * configuration: + *
+ * {@code
+ *
+ *
+ *
+ *
+ *
+ *
+ * }
+ * the examples are equivalent save that in XML a fixed-rate period is used
+ * instead of a custom {@code Trigger} implementation; this is because the
+ * {@code task:} namespace {@code scheduled} cannot easily expose such support. This is
+ * but one demonstration how the code-based approach allows for maximum configurability
+ * through direct access to actual componentry.+ * * @author Chris Beams * @since 3.1 * @see Scheduled diff --git a/org.springframework.context/src/main/java/org/springframework/scheduling/annotation/SchedulingConfiguration.java b/org.springframework.context/src/main/java/org/springframework/scheduling/annotation/SchedulingConfiguration.java index 2808d8599e7..52e97332ea8 100644 --- a/org.springframework.context/src/main/java/org/springframework/scheduling/annotation/SchedulingConfiguration.java +++ b/org.springframework.context/src/main/java/org/springframework/scheduling/annotation/SchedulingConfiguration.java @@ -23,12 +23,13 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Role; /** - * Configures a {@link ScheduledAnnotationBeanPostProcessor} bean capable of - * processing Spring's @{@link Scheduled} annotation. + * {@code @Configuration} class that registers a {@link + * ScheduledAnnotationBeanPostProcessor} bean capable of processing Spring's @{@link + * Scheduled} annotation. * - *
This {@code @Configuration} class is automatically imported when using - * the @{@link EnableScheduling} annotation. See {@code @EnableScheduling} - * Javadoc for complete usage details. + *
This configuration class is automatically imported when using the @{@link + * EnableScheduling} annotation. See {@code @EnableScheduling} Javadoc for complete usage + * details. * * @author Chris Beams * @since 3.1 diff --git a/org.springframework.context/src/main/java/org/springframework/scheduling/annotation/SchedulingConfigurer.java b/org.springframework.context/src/main/java/org/springframework/scheduling/annotation/SchedulingConfigurer.java index 466c4eb14e7..d4787c0e4cc 100644 --- a/org.springframework.context/src/main/java/org/springframework/scheduling/annotation/SchedulingConfigurer.java +++ b/org.springframework.context/src/main/java/org/springframework/scheduling/annotation/SchedulingConfigurer.java @@ -18,6 +18,21 @@ package org.springframework.scheduling.annotation; import org.springframework.scheduling.config.ScheduledTaskRegistrar; +/** + * Interface to be implemented by @{@link org.springframework.context.annotation.Configuration} + * classes annotated with @{@link EnableScheduling} that wish to register scheduled tasks + * in a programmatic fashion as opposed to the declarative approach of + * using the @{@link Scheduled} annotation. For example, this may be necessary when + * implementing {@link org.springframework.scheduling.Trigger Trigger}-based tasks, which + * are not supported by the {@code @Scheduled} annotation. + * + *
See @{@link EnableScheduling} for detailed usage examples. + * + * @author Chris Beams + * @since 3.1 + * @see EnableScheduling + * @see ScheduledTaskRegistrar + */ public interface SchedulingConfigurer { void configureTasks(ScheduledTaskRegistrar taskRegistrar); diff --git a/org.springframework.context/src/main/java/org/springframework/scheduling/config/ScheduledTaskRegistrar.java b/org.springframework.context/src/main/java/org/springframework/scheduling/config/ScheduledTaskRegistrar.java index 0caa68aa10b..3f4adc49074 100644 --- a/org.springframework.context/src/main/java/org/springframework/scheduling/config/ScheduledTaskRegistrar.java +++ b/org.springframework.context/src/main/java/org/springframework/scheduling/config/ScheduledTaskRegistrar.java @@ -36,8 +36,16 @@ import org.springframework.util.Assert; * Helper bean for registering tasks with a {@link TaskScheduler}, * typically using cron expressions. * + *
As of Spring 3.1, {@code ScheduledTaskRegistrar} has a more prominent user-facing
+ * role when used in conjunction with the @{@link
+ * org.springframework.scheduling.annotation.EnableAsync EnableAsync} annotation and its
+ * {@link org.springframework.scheduling.annotation.SchedulingConfigurer
+ * SchedulingConfigurer} callback interface.
+ *
* @author Juergen Hoeller
* @since 3.0
+ * @see org.springframework.scheduling.annotation.EnableAsync
+ * @see org.springframework.scheduling.annotation.SchedulingConfigurer
*/
public class ScheduledTaskRegistrar implements InitializingBean, DisposableBean {
@@ -53,7 +61,7 @@ public class ScheduledTaskRegistrar implements InitializingBean, DisposableBean
private Map