java crontriggerbean_spring定时器—-CronTriggerBean

java crontriggerbean_spring定时器—-CronTriggerBean1.层次结构2.CronTriggerBean.javapublicclassCronTriggerBeanextendsCronTriggerimplementsJobDetailAwareTrigger,BeanNameAware,InitializingBean{/**ConstantsfortheCronTriggerclass*/privatestat…

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

今天的文章java crontriggerbean_spring定时器—-CronTriggerBean分享到此就结束了,感谢您的阅读,如果确实帮到您,您可以动动手指转发给其他人。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/29009.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注