Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
358cbf43
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
358cbf43
编写于
5月 07, 2011
作者:
C
Chris Beams
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polish @EnableScheduling Javadoc
上级
b7f4f2b5
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
148 addition
and
2 deletion
+148
-2
org.springframework.context/src/main/java/org/springframework/scheduling/annotation/EnableScheduling.java
...ringframework/scheduling/annotation/EnableScheduling.java
+123
-1
org.springframework.context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessor.java
...ling/annotation/ScheduledAnnotationBeanPostProcessor.java
+12
-1
org.springframework.context/src/main/java/org/springframework/scheduling/annotation/SchedulingConfiguration.java
...mework/scheduling/annotation/SchedulingConfiguration.java
+13
-0
未找到文件。
org.springframework.context/src/main/java/org/springframework/scheduling/annotation/EnableScheduling.java
浏览文件 @
358cbf43
...
...
@@ -21,14 +21,136 @@ import java.lang.annotation.ElementType;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
import
java.util.concurrent.Executor
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.scheduling.Trigger
;
import
org.springframework.scheduling.config.ScheduledTaskRegistrar
;
/**
* Enables Spring's scheduled task execution capability.
* Enables Spring's scheduled task execution capability, similar to
* functionality found in Spring's {@code <task:*>} XML namespace. To be used
* on @{@link Configuration} classes as follows:
*
* <pre class="code">
* @Configuration
* @EnableScheduling
* public class AppConfig {
* // various @Bean definitions
* }</pre>
*
* This enables detection of @{@link Scheduled} annotations on any Spring-managed
* bean in the container. For example, given a class {@code MyTask}
*
* <pre class="code">
* package com.myco.tasks;
*
* public class MyTask {
* @Scheduled(fixedRate=1000)
* public void work() {
* // task execution logic
* }
* }</pre>
*
* the following configuration would ensure that {@code MyTask.work()} is called
* once every 1000 ms:
*
* <pre class="code">
* @Configuration
* @EnableScheduling
* public class AppConfig {
* @Bean
* public MyTask task() {
* return new MyTask();
* }
* }</pre>
*
* Alternatively, if {@code MyTask} were annotated with {@code @Component}, the
* following configuration would ensure that its {@code @Scheduled} method is
* invoked at the desired interval:
*
* <pre class="code">
* @Configuration
* @ComponentScan(basePackages="com.myco.tasks")
* public class AppConfig {
* }</pre>
*
* Methods annotated with {@code @Scheduled} may even be declared directly within
* {@code @Configuration} classes:
*
* <pre class="code">
* @Configuration
* @EnableScheduling
* public class AppConfig {
* @Scheduled(fixedRate=1000)
* public void work() {
* // task execution logic
* }
* }</pre>
*
* In all of the above scenarios, a default single-threaded task executor is used.
* When more control is desired, a {@code @Configuration} class may implement
* {@link SchedulingConfigurer}. This allows access to the underlying
* {@link ScheduledTaskRegistrar} instance. For example, the following example
* demonstrates how to customize the {@link Executor} used to execute scheduled
* tasks:
*
* <pre class="code">
* @Configuration
* @EnableScheduling
* public class AppConfig implements SchedulingConfigurer {
* @Override
* public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
* taskRegistrar.setScheduler(taskExecutor());
* }
*
* @Bean
* public Executor taskExecutor() {
* return Executors.newScheduledThreadPool(100);
* }
* }</pre>
*
* Implementing {@code SchedulingConfigurer} also allows for fine-grained
* control over task registration via the {@code ScheduledTaskRegistrar}.
* For example, the following configures the execution of a particular bean
* method per a custom {@code Trigger} implementation:
*
* <pre class="code">
* @Configuration
* @EnableScheduling
* public class AppConfig implements SchedulingConfigurer {
* @Override
* public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
* taskRegistrar.setScheduler(taskExecutor());
* taskRegistrar.addTriggerTask(
* addTriggerTask(
* new Runnable() {
* task().work();
* },
* new CustomTrigger()
* );
* }
*
* @Bean
* public Executor taskExecutor() {
* return Executors.newScheduledThreadPool(100);
* }
*
* @Bean
* public MyTask task() {
* return new MyTask();
* }
* }</pre>
*
* @author Chris Beams
* @since 3.1
* @see Scheduled
* @see SchedulingConfiguration
* @see SchedulingConfigurer
* @see ScheduledTaskRegistrar
* @see Trigger
* @see ScheduledAnnotationBeanPostProcessor
*/
@Target
(
ElementType
.
TYPE
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
...
...
org.springframework.context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessor.java
浏览文件 @
358cbf43
...
...
@@ -32,6 +32,7 @@ import org.springframework.context.event.ContextRefreshedEvent;
import
org.springframework.core.Ordered
;
import
org.springframework.core.annotation.AnnotationUtils
;
import
org.springframework.scheduling.TaskScheduler
;
import
org.springframework.scheduling.Trigger
;
import
org.springframework.scheduling.config.ScheduledTaskRegistrar
;
import
org.springframework.scheduling.support.ScheduledMethodRunnable
;
import
org.springframework.util.Assert
;
...
...
@@ -40,15 +41,25 @@ import org.springframework.util.ReflectionUtils.MethodCallback;
import
org.springframework.util.StringValueResolver
;
/**
* Bean post-processor that registers methods annotated with
{@link Scheduled @
Scheduled}
* Bean post-processor that registers methods annotated with
@{@link
Scheduled}
* to be invoked by a {@link org.springframework.scheduling.TaskScheduler} according
* to the "fixedRate", "fixedDelay", or "cron" expression provided via the annotation.
*
* <p>This post-processor is automatically registered by Spring's
* {@code <task:annotation-driven>} XML element, and also by the @{@link EnableScheduling}
* annotation.
*
* <p>Auto-detects any {@link SchedulingConfigurer} instances in the container,
* allowing for customization of the scheduler to be used or for fine-grained control
* over task registration (e.g. registration of {@link Trigger} tasks.
* See @{@link EnableScheduling} Javadoc for complete usage details.
*
* @author Mark Fisher
* @author Juergen Hoeller
* @author Chris Beams
* @since 3.0
* @see Scheduled
* @see EnableScheduling
* @see SchedulingConfigurer
* @see org.springframework.scheduling.TaskScheduler
* @see org.springframework.scheduling.config.ScheduledTaskRegistrar
...
...
org.springframework.context/src/main/java/org/springframework/scheduling/annotation/SchedulingConfiguration.java
浏览文件 @
358cbf43
...
...
@@ -22,6 +22,19 @@ import org.springframework.context.annotation.Bean;
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.
*
* <p>This {@code @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
* @see EnableScheduling
* @see ScheduledAnnotationBeanPostProcessor
*/
@Configuration
public
class
SchedulingConfiguration
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录