java crontriggerbean_spring定时器----CronTriggerBean

1. 层次结构

0d360b89462f2591edd92d131568e024.png

2. CronTriggerBean

.java

public class CronTriggerBean extends CronTrigger

implements JobDetailAwareTrigger, BeanNameAware, InitializingBean {

/** Constants for the CronTrigger class */

private static final Constants constants = new Constants(CronTrigger.class);

private JobDetail jobDetail;

private String beanName;

/**

* Register objects in the JobDataMap via a given Map.

*/

public void setJobDataAsMap(Map jobDataAsMap) {

getJobDataMap().putAll(jobDataAsMap);

}

/**

* Set the misfire instruction via the name of the corresponding

*/

public void setMisfireInstructionName(String constantName) {

setMisfireInstruction(constants.asNumber(constantName).intValue());

}

/**

* Set a list of TriggerListener names for this job, referring to

* non-global TriggerListeners registered with the Scheduler.

*/

public void setTriggerListenerNames(String[] names) {

for (int i = 0; i < names.length; i++) {

addTriggerListener(names[i]);

}

}

/**

* Set the JobDetail that this trigger should be associated with.

*/

public void setJobDetail(JobDetail jobDetail) {

this.jobDetail = jobDetail;

}

public JobDetail getJobDetail() {

return this.jobDetail;

}

public void setBeanName(String beanName) {

this.beanName = beanName;

}

public void afterPropertiesSet() throws ParseException {

if (getName() == null) {

setName(this.beanName);

}

if (getGroup() == null) {

setGroup(Scheduler.DEFAULT_GROUP);

}

if (getStartTime() == null) {

setStartTime(new Date());

}

if (getTimeZone() == null) {

setTimeZone(TimeZone.getDefault());

}

if (this.jobDetail != null) {

setJobName(this.jobDetail.getName());

setJobGroup(this.jobDetail.getGroup());

}

}

}     3. 定时器配置规则

df6cdf6365503dd802bfa87af5be93d3.png

示例:

5a47a523af2ef7ca3b0d9676c725a622.png

4. 说明        <1> 通常只用两个属性 JobDetail和CronExpression,前者确定任务的名称、组等信息,后者确定任务的触发时间、间隔时间等信息;

<2> CronExpression属性在CronTrigger类中。

<3> 示例:  0/15 * * * *   执行时刻:0,15,30,45

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值