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. 定時器配置規則

 示例:   java

  4. 說明 this

       <1> 一般只用兩個屬性 JobDetail和CronExpression,前者肯定任務的名稱、組等信息,後者肯定任務的觸發時間、間隔時間等信息;        <2> CronExpression屬性在CronTrigger類中。       <3> 示例:  0/15 * * * *   執行時刻:0,15,30,45
相關文章
相關標籤/搜索