Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
4ca54fb4
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,体验更适合开发者的 AI 搜索 >>
提交
4ca54fb4
编写于
1月 08, 2010
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fixed @Scheduled processing to kick in once only even in an ApplicationContext hierarchy (SPR-6656)
上级
2ef40d24
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
28 addition
and
17 deletion
+28
-17
org.springframework.context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessor.java
...ling/annotation/ScheduledAnnotationBeanPostProcessor.java
+28
-17
未找到文件。
org.springframework.context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessor.java
浏览文件 @
4ca54fb4
...
...
@@ -24,6 +24,8 @@ import org.springframework.aop.support.AopUtils;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.factory.DisposableBean
;
import
org.springframework.beans.factory.config.BeanPostProcessor
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContextAware
;
import
org.springframework.context.ApplicationListener
;
import
org.springframework.context.event.ContextRefreshedEvent
;
import
org.springframework.core.Ordered
;
...
...
@@ -35,19 +37,23 @@ import org.springframework.util.ReflectionUtils;
import
org.springframework.util.ReflectionUtils.MethodCallback
;
/**
* Bean post-processor that registers methods annotated with
*
{@link Scheduled @Scheduled} to be invoked by a TaskScheduler
according
* to the
fixedRate, fixedDelay, or cron
expression provided via the annotation.
* Bean post-processor that registers methods annotated with
{@link Scheduled @Scheduled}
*
to be invoked by a {@link org.springframework.scheduling.TaskScheduler}
according
* to the
"fixedRate", "fixedDelay", or "cron"
expression provided via the annotation.
*
* @author Mark Fisher
* @author Juergen Hoeller
* @since 3.0
* @see Scheduled
* @see org.springframework.scheduling.TaskScheduler
*/
public
class
ScheduledAnnotationBeanPostProcessor
implements
BeanPostProcessor
,
Ordered
,
ApplicationListener
<
ContextRefreshedEvent
>,
DisposableBean
{
Application
ContextAware
,
Application
Listener
<
ContextRefreshedEvent
>,
DisposableBean
{
private
Object
scheduler
;
private
ApplicationContext
applicationContext
;
private
final
ScheduledTaskRegistrar
registrar
=
new
ScheduledTaskRegistrar
();
private
final
Map
<
Runnable
,
String
>
cronTasks
=
new
HashMap
<
Runnable
,
String
>();
...
...
@@ -58,20 +64,23 @@ public class ScheduledAnnotationBeanPostProcessor implements BeanPostProcessor,
/**
* Set the {@link org.springframework.scheduling.TaskScheduler} that will
* invoke the scheduled methods or a
* {@link java.util.concurrent.ScheduledExecutorService} to be wrapped
* within an instance of
* {@link org.springframework.scheduling.concurrent.ConcurrentTaskScheduler}.
* Set the {@link org.springframework.scheduling.TaskScheduler} that will invoke
* the scheduled methods, or a {@link java.util.concurrent.ScheduledExecutorService}
* to be wrapped as a TaskScheduler.
*/
public
void
setScheduler
(
Object
scheduler
)
{
this
.
scheduler
=
scheduler
;
}
public
void
setApplicationContext
(
ApplicationContext
applicationContext
)
{
this
.
applicationContext
=
applicationContext
;
}
public
int
getOrder
()
{
return
LOWEST_PRECEDENCE
;
}
public
Object
postProcessBeforeInitialization
(
Object
bean
,
String
beanName
)
throws
BeansException
{
return
bean
;
}
...
...
@@ -110,13 +119,13 @@ public class ScheduledAnnotationBeanPostProcessor implements BeanPostProcessor,
if
(
fixedDelay
>=
0
)
{
Assert
.
isTrue
(!
processedSchedule
,
errorMessage
);
processedSchedule
=
true
;
fixedDelayTasks
.
put
(
runnable
,
new
Long
(
fixedDelay
)
);
fixedDelayTasks
.
put
(
runnable
,
fixedDelay
);
}
long
fixedRate
=
annotation
.
fixedRate
();
if
(
fixedRate
>=
0
)
{
Assert
.
isTrue
(!
processedSchedule
,
errorMessage
);
processedSchedule
=
true
;
fixedRateTasks
.
put
(
runnable
,
new
Long
(
fixedRate
)
);
fixedRateTasks
.
put
(
runnable
,
fixedRate
);
}
Assert
.
isTrue
(
processedSchedule
,
errorMessage
);
}
...
...
@@ -126,14 +135,16 @@ public class ScheduledAnnotationBeanPostProcessor implements BeanPostProcessor,
}
public
void
onApplicationEvent
(
ContextRefreshedEvent
event
)
{
if
(
scheduler
!=
null
)
{
this
.
registrar
.
setScheduler
(
scheduler
);
if
(
event
.
getApplicationContext
()
==
this
.
applicationContext
)
{
if
(
this
.
scheduler
!=
null
)
{
this
.
registrar
.
setScheduler
(
this
.
scheduler
);
}
this
.
registrar
.
setCronTasks
(
this
.
cronTasks
);
this
.
registrar
.
setFixedDelayTasks
(
this
.
fixedDelayTasks
);
this
.
registrar
.
setFixedRateTasks
(
this
.
fixedRateTasks
);
this
.
registrar
.
afterPropertiesSet
();
}
}
public
void
destroy
()
throws
Exception
{
if
(
this
.
registrar
!=
null
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录