spring定时器----CronTriggerBean

    1. 层次结构
       spring定时器----CronTriggerBean_第1张图片
    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. 定时器配置规则
spring定时器----CronTriggerBean_第2张图片

 示例: spring定时器----CronTriggerBean_第3张图片 

  4. 说明

       <1> 通常只用两个属性 JobDetail和CronExpression,前者确定任务的名称、组等信息,后者确定任务的触发时间、间隔时间等信息;
       <2> CronExpression属性在CronTrigger类中。
      <3> 示例:  0/15 * * * *   执行时刻:0,15,30,45

你可能感兴趣的:(spring定时器----CronTriggerBean)