Skip to content

Commit a8418d3

Browse files
committed
Fixed XML example for setup of scheduled tasks
Issue: SPR-14145 (cherry picked from commit 550a320)
1 parent dc20a32 commit a8418d3

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

spring-context/src/main/java/org/springframework/scheduling/annotation/EnableScheduling.java

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2016 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.
@@ -37,16 +37,18 @@
3737
* @Configuration
3838
* @EnableScheduling
3939
* public class AppConfig {
40+
*
4041
* // various @Bean definitions
4142
* }</pre>
4243
*
4344
* This enables detection of @{@link Scheduled} annotations on any Spring-managed
44-
* bean in the container. For example, given a class {@code MyTask}
45+
* bean in the container. For example, given a class {@code MyTask}
4546
*
4647
* <pre class="code">
4748
* package com.myco.tasks;
4849
*
4950
* public class MyTask {
51+
*
5052
* &#064;Scheduled(fixedRate=1000)
5153
* public void work() {
5254
* // task execution logic
@@ -60,6 +62,7 @@
6062
* &#064;Configuration
6163
* &#064;EnableScheduling
6264
* public class AppConfig {
65+
*
6366
* &#064;Bean
6467
* public MyTask task() {
6568
* return new MyTask();
@@ -72,6 +75,7 @@
7275
*
7376
* <pre class="code">
7477
* &#064;Configuration
78+
* &#064;EnableScheduling
7579
* &#064;ComponentScan(basePackages="com.myco.tasks")
7680
* public class AppConfig {
7781
* }</pre>
@@ -83,6 +87,7 @@
8387
* &#064;Configuration
8488
* &#064;EnableScheduling
8589
* public class AppConfig {
90+
*
8691
* &#064;Scheduled(fixedRate=1000)
8792
* public void work() {
8893
* // task execution logic
@@ -100,6 +105,7 @@
100105
* &#064;Configuration
101106
* &#064;EnableScheduling
102107
* public class AppConfig implements SchedulingConfigurer {
108+
*
103109
* &#064;Override
104110
* public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
105111
* taskRegistrar.setScheduler(taskExecutor());
@@ -111,11 +117,11 @@
111117
* }
112118
* }</pre>
113119
*
114-
* Note in the example above the use of {@code @Bean(destroyMethod="shutdown")}. This
115-
* ensures that the task executor is properly shut down when the Spring application
116-
* context itself is closed.
120+
* <p>Note in the example above the use of {@code @Bean(destroyMethod="shutdown")}.
121+
* This ensures that the task executor is properly shut down when the Spring
122+
* application context itself is closed.
117123
*
118-
* Implementing {@code SchedulingConfigurer} also allows for fine-grained
124+
* <p>Implementing {@code SchedulingConfigurer} also allows for fine-grained
119125
* control over task registration via the {@code ScheduledTaskRegistrar}.
120126
* For example, the following configures the execution of a particular bean
121127
* method per a custom {@code Trigger} implementation:
@@ -124,6 +130,7 @@
124130
* &#064;Configuration
125131
* &#064;EnableScheduling
126132
* public class AppConfig implements SchedulingConfigurer {
133+
*
127134
* &#064;Override
128135
* public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
129136
* taskRegistrar.setScheduler(taskScheduler());
@@ -150,22 +157,32 @@
150157
*
151158
* <p>For reference, the example above can be compared to the following Spring XML
152159
* configuration:
160+
*
153161
* <pre class="code">
154162
* {@code
155163
* <beans>
164+
*
156165
* <task:annotation-driven scheduler="taskScheduler"/>
166+
*
157167
* <task:scheduler id="taskScheduler" pool-size="42"/>
158-
* <task:scheduled ref="myTask" method="work" fixed-rate="1000"/>
168+
*
169+
* <task:scheduled-tasks scheduler="taskScheduler">
170+
* <task:scheduled ref="myTask" method="work" fixed-rate="1000"/>
171+
* </task:scheduled-tasks>
172+
*
159173
* <bean id="myTask" class="com.foo.MyTask"/>
174+
*
160175
* </beans>
161176
* }</pre>
162-
* the examples are equivalent save that in XML a <em>fixed-rate</em> period is used
177+
*
178+
* The examples are equivalent save that in XML a <em>fixed-rate</em> period is used
163179
* instead of a custom <em>{@code Trigger}</em> implementation; this is because the
164180
* {@code task:} namespace {@code scheduled} cannot easily expose such support. This is
165181
* but one demonstration how the code-based approach allows for maximum configurability
166182
* through direct access to actual componentry.<p>
167183
*
168184
* @author Chris Beams
185+
* @author Juergen Hoeller
169186
* @since 3.1
170187
* @see Scheduled
171188
* @see SchedulingConfiguration

0 commit comments

Comments
 (0)