Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dk131072
spring-framework
提交
90652bf8
S
spring-framework
项目概览
dk131072
/
spring-framework
与 Fork 源项目一致
从无法访问的项目Fork
通知
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,发现更多精彩内容 >>
提交
90652bf8
编写于
9月 14, 2009
作者:
R
Rob Harrop
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[SPR-5727] CronTriggerBean supports start delay
上级
320f08ac
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
99 addition
and
0 deletion
+99
-0
org.springframework.context.support/src/main/java/org/springframework/scheduling/quartz/CronTriggerBean.java
...rg/springframework/scheduling/quartz/CronTriggerBean.java
+20
-0
org.springframework.context.support/src/test/java/org/springframework/scheduling/quartz/CronTriggerBeanTests.java
...ringframework/scheduling/quartz/CronTriggerBeanTests.java
+79
-0
未找到文件。
org.springframework.context.support/src/main/java/org/springframework/scheduling/quartz/CronTriggerBean.java
浏览文件 @
90652bf8
...
...
@@ -27,6 +27,7 @@ import org.quartz.Scheduler;
import
org.springframework.beans.factory.BeanNameAware
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.core.Constants
;
import
org.springframework.util.Assert
;
/**
* Convenience subclass of Quartz's {@link org.quartz.CronTrigger} class,
...
...
@@ -70,6 +71,7 @@ public class CronTriggerBean extends CronTrigger
private
String
beanName
;
private
long
startDelay
;
/**
* Register objects in the JobDataMap via a given Map.
...
...
@@ -121,6 +123,20 @@ public class CronTriggerBean extends CronTrigger
this
.
jobDetail
=
jobDetail
;
}
/**
* Set the start delay in milliseconds.
* <p>The start delay is added to the current system time
* (when the bean starts) to control the {@link #setStartTime start time}
* of the trigger.
* <p>If the start delay is non-zero it will <strong>always</strong>
* take precedence over start time.
* @param startDelay the start delay, in milliseconds.
*/
public
void
setStartDelay
(
long
startDelay
)
{
Assert
.
state
(
startDelay
>=
0
,
"Start delay cannot be negative."
);
this
.
startDelay
=
startDelay
;
}
public
JobDetail
getJobDetail
()
{
return
this
.
jobDetail
;
}
...
...
@@ -131,6 +147,10 @@ public class CronTriggerBean extends CronTrigger
public
void
afterPropertiesSet
()
throws
Exception
{
if
(
this
.
startDelay
>
0
)
{
setStartTime
(
new
Date
(
System
.
currentTimeMillis
()
+
this
.
startDelay
));
}
if
(
getName
()
==
null
)
{
setName
(
this
.
beanName
);
}
...
...
org.springframework.context.support/src/test/java/org/springframework/scheduling/quartz/CronTriggerBeanTests.java
0 → 100644
浏览文件 @
90652bf8
/*
* Copyright 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.scheduling.quartz
;
import
java.util.Date
;
import
java.util.Calendar
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
/** @author Rob Harrop */
public
class
CronTriggerBeanTests
{
@Test
(
expected
=
IllegalStateException
.
class
)
public
void
testInvalidStartDelay
()
{
createTriggerBean
().
setStartDelay
(-
1
);
}
@Test
public
void
testStartTime
()
throws
Exception
{
CronTriggerBean
bean
=
createTriggerBean
();
Date
startTime
=
new
Date
(
System
.
currentTimeMillis
()
+
1234L
);
bean
.
setStartTime
(
startTime
);
bean
.
afterPropertiesSet
();
assertTimeEquals
(
startTime
,
bean
.
getStartTime
());
}
@Test
public
void
testStartDelay
()
throws
Exception
{
CronTriggerBean
bean
=
createTriggerBean
();
long
startDelay
=
1234L
;
Date
startTime
=
new
Date
(
System
.
currentTimeMillis
()
+
startDelay
);
bean
.
setStartDelay
(
startDelay
);
bean
.
afterPropertiesSet
();
assertTimeEquals
(
startTime
,
bean
.
getStartTime
());
}
@Test
public
void
testStartDelayOverridesStartTime
()
throws
Exception
{
CronTriggerBean
bean
=
createTriggerBean
();
long
startDelay
=
1234L
;
Date
startTime
=
new
Date
(
System
.
currentTimeMillis
()
+
startDelay
);
bean
.
setStartTime
(
new
Date
(
System
.
currentTimeMillis
()
+
123456789L
));
bean
.
setStartDelay
(
startDelay
);
bean
.
afterPropertiesSet
();
assertTimeEquals
(
startTime
,
bean
.
getStartTime
());
}
private
CronTriggerBean
createTriggerBean
()
{
CronTriggerBean
triggerBean
=
new
CronTriggerBean
();
triggerBean
.
setName
(
"test"
);
return
triggerBean
;
}
private
void
assertTimeEquals
(
Date
a
,
Date
b
)
{
Calendar
ca
=
Calendar
.
getInstance
();
ca
.
setTime
(
a
);
ca
.
set
(
Calendar
.
MILLISECOND
,
0
);
Calendar
cb
=
Calendar
.
getInstance
();
cb
.
setTime
(
b
);
cb
.
set
(
Calendar
.
MILLISECOND
,
0
);
assertEquals
(
ca
,
cb
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录