Java Code Examples for org.springframework.scheduling.quartz.CronTriggerFactoryBean#setCronExpression()

The following examples show how to use org.springframework.scheduling.quartz.CronTriggerFactoryBean#setCronExpression() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JobScheduler.java    From DataHubSystem with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void afterPropertiesSet () throws Exception
{
   Map<String, AbstractJob> webappBeanNames =
      applicationContext.getBeansOfType (AbstractJob.class);
   triggers = new HashMap<> ();
   for (String webappBeanName : webappBeanNames.keySet ())
   {
      AbstractJob cron = webappBeanNames.get (webappBeanName);
      CronTriggerFactoryBean trigger = new CronTriggerFactoryBean ();
      JobDetail job = JobBuilder.newJob (cron.getClass ()).
         storeDurably (true).build ();
      trigger.setJobDetail (job);
      trigger.setCronExpression (cron.getCronExpression ());
      trigger.setName (webappBeanName + "Trigger");
      trigger.afterPropertiesSet ();
      triggers.put (cron.getClass(), trigger.getObject ());
   }
   super.setTriggers (triggers.values ().toArray (
      new Trigger[triggers.size ()]));
   super.setJobFactory (autowiringJobFactory);
   super.afterPropertiesSet ();
}
 
Example 2
Source File: Neutron.java    From Milkomeda with MIT License 5 votes vote down vote up
/**
 * cron表达式触发器
 * @param triggerName 触发器名称
 * @param triggerGroup 触发器所在组
 * @param cronExpression cron表达式
 * @return CronTrigger
 * @throws ParseException cron解析异常
 */
public static CronTrigger createCronTrigger(String triggerName, String triggerGroup, String cronExpression) throws ParseException {
    CronTriggerFactoryBean factoryBean = new CronTriggerFactoryBean();
    factoryBean.setName(triggerName);
    factoryBean.setGroup(triggerGroup);
    factoryBean.setCronExpression(cronExpression);
    // 由于是手动创建的Bean,需要调用afterPropertiesSet()属性初始化方法
    factoryBean.afterPropertiesSet();
    return factoryBean.getObject();
}
 
Example 3
Source File: QuartzConfigration.java    From Tbed with GNU Affero General Public License v3.0 5 votes vote down vote up
@Bean(name = "secondTrigger")
public CronTriggerFactoryBean secondTrigger(JobDetail secondJobDetail) {
    CronTriggerFactoryBean trigger = new CronTriggerFactoryBean();
    trigger.setJobDetail(secondJobDetail);
    // cron表达式
    trigger.setCronExpression(Expression);
    //trigger.setCronExpression("0 0/1 * * * ?");
    return trigger;
}
 
Example 4
Source File: PacmanQuartzConfiguration.java    From pacbot with Apache License 2.0 5 votes vote down vote up
public CronTriggerFactoryBean createCronTrigger(JobDetail jobDetail, String cronExpression) {
	CronTriggerFactoryBean factoryBean = new CronTriggerFactoryBean();
	factoryBean.setJobDetail(jobDetail);
	factoryBean.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
	factoryBean.setCronExpression(cronExpression);
	factoryBean.setMisfireInstruction(SimpleTrigger.MISFIRE_INSTRUCTION_FIRE_NOW);
	return factoryBean;
}
 
Example 5
Source File: SchedulerConfig.java    From zkdoctor with Apache License 2.0 5 votes vote down vote up
/**
 * 创建cron触发器
 *
 * @param jobDetail      job信息
 * @param cronExpression cron表达式
 * @param triggerName    触发器名称
 * @param triggerGroup   触发器组
 * @return
 */
private CronTriggerFactoryBean createCronTrigger(JobDetail jobDetail, String cronExpression,
                                                 String triggerName, String triggerGroup) {
    CronTriggerFactoryBean factoryBean = new CronTriggerFactoryBean();
    factoryBean.setJobDetail(jobDetail);
    factoryBean.setName(triggerName);
    factoryBean.setGroup(triggerGroup);
    factoryBean.setCronExpression(cronExpression);
    factoryBean.setMisfireInstruction(SimpleTrigger.MISFIRE_INSTRUCTION_FIRE_NOW);
    return factoryBean;
}
 
Example 6
Source File: SpringBootAsyncProducerApplication.java    From Spring-Boot-2.0-Projects with MIT License 5 votes vote down vote up
@Bean
public CronTriggerFactoryBean trigger(JobDetail job, @Value("${images.cron}") String imagesCron) {
    CronTriggerFactoryBean cronTriggerFactoryBean = new CronTriggerFactoryBean();
    cronTriggerFactoryBean.setCronExpression(imagesCron);
    cronTriggerFactoryBean.setJobDetail(job);
    return cronTriggerFactoryBean;
}
 
Example 7
Source File: QuartzConfigration.java    From springBoot-study with Apache License 2.0 5 votes vote down vote up
@Bean(name = "jobTrigger")  
    public CronTriggerFactoryBean cronJobTrigger(MethodInvokingJobDetailFactoryBean jobDetail) {  
        CronTriggerFactoryBean tigger = new CronTriggerFactoryBean();  
        tigger.setJobDetail(jobDetail.getObject());  
//        tigger.setCronExpression("0/30 * * * * ?");// 表示每隔30秒钟执行一次
        tigger.setCronExpression("1/30 * * * * ?");// 表示每隔30秒钟执行一次
        //tigger.set
        tigger.setName("myTigger");// trigger的name  
        return tigger;  

    }
 
Example 8
Source File: RecoverScheduledJob.java    From distributed-transaction-process with MIT License 5 votes vote down vote up
/**
 * 初始化方法,Spring启动时执行.
 */
public void init() {

    try {
    	// MethodInvokingJobDetailFactoryBean 负责生成具体的任务,只需要指定某个对象的某个方法,在触发器触发时,即调用指定对象的指定方法。
        MethodInvokingJobDetailFactoryBean jobDetail = new MethodInvokingJobDetailFactoryBean();
        // 指定该任务对应的调用对象,这个对象所属的类无需实现任何接口
        jobDetail.setTargetObject(transactionRecovery);
        // 指定在targetObject对象中某个的方法(此处调用TransactionRecovery中的startRecover方法)
        jobDetail.setTargetMethod("startRecover");
        // 设置任务名称
        jobDetail.setName("transactionRecoveryJob");
        // 是否允许任务并发执行,类默认是并发执行的,这时候如果不设置“concurrent”为false,很可能带来并发或者死锁的问题,而且几率较小,不容易复现,
        // 设置为false表示等上一个任务执行完后再开启新的任务
        jobDetail.setConcurrent(false);
        jobDetail.afterPropertiesSet();

        // 触发器生成器类,用被指定的调度器调度生成指定规则的触发器对象
        // 该类负责在spring容器中创建一个触发器,该类的ID应该在SchedulerFactoryBean属性的List中被引用,这样这个触发器才能保证被某个指定调度器调度
        CronTriggerFactoryBean cronTrigger = new CronTriggerFactoryBean();
        // 设置触发器名称
        cronTrigger.setBeanName("transactionRecoveryCronTrigger");
        // 触发规则(这里通过事务配置器获取事务恢复定时任务规则)
        cronTrigger.setCronExpression(transactionConfigurator.getRecoverConfig().getCronExpression());
        cronTrigger.afterPropertiesSet();

        // 设置调度任务
        scheduler.scheduleJob(jobDetail.getObject(), cronTrigger.getObject());
        // 启动任务调度器
        scheduler.start();

    } catch (Exception e) {
        throw new SystemException(e);
    }
}
 
Example 9
Source File: QuartzConfiguration.java    From multiapps-controller with Apache License 2.0 5 votes vote down vote up
@Inject
@Bean
public CronTriggerFactoryBean cleanUpCronTriggerFactoryBean(ApplicationConfiguration configuration) {
    CronTriggerFactoryBean factory = new CronTriggerFactoryBean();
    factory.setJobDetail(cleanUpJobDetail().getObject());
    factory.setCronExpression(configuration.getCronExpressionForOldData());
    factory.setMisfireInstruction(org.quartz.CronTrigger.MISFIRE_INSTRUCTION_FIRE_ONCE_NOW);
    factory.setGroup(TRIGGER_GROUP);
    factory.setName(CLEAN_UP_TRIGGER_NAME);
    return factory;
}
 
Example 10
Source File: QuartzConfig.java    From lemonaid with MIT License 5 votes vote down vote up
@Bean
public CronTriggerFactoryBean gravatarTrigger() {
	CronTriggerFactoryBean cronTriggerFactoryBean = new CronTriggerFactoryBean();
	cronTriggerFactoryBean.setJobDetail(gravatarJob().getObject());
	cronTriggerFactoryBean.setCronExpression("0 30 * * * ?"); // Every hour
	cronTriggerFactoryBean.setGroup("lemonaid-quartz");
	return cronTriggerFactoryBean;
}
 
Example 11
Source File: QuartzConfig.java    From lemonaid with MIT License 5 votes vote down vote up
@Bean
public CronTriggerFactoryBean locationTrigger() {
	CronTriggerFactoryBean cronTriggerFactoryBean = new CronTriggerFactoryBean();
	cronTriggerFactoryBean.setJobDetail(locationJob().getObject());
	cronTriggerFactoryBean.setCronExpression("0 15 0 * * ?"); // Every day
	cronTriggerFactoryBean.setGroup("lemonaid-quartz");
	return cronTriggerFactoryBean;
}
 
Example 12
Source File: QuartzConfig.java    From lemonaid with MIT License 5 votes vote down vote up
@Bean
public CronTriggerFactoryBean insideTrackTrigger() {
	CronTriggerFactoryBean cronTriggerFactoryBean = new CronTriggerFactoryBean();
	cronTriggerFactoryBean.setJobDetail(insideTrackJob().getObject());
	cronTriggerFactoryBean.setCronExpression("0 0 * * * ?"); // Every hour
	cronTriggerFactoryBean.setGroup("lemonaid-quartz");
	return cronTriggerFactoryBean;
}
 
Example 13
Source File: RepositoryStatisticsCronJob.java    From mojito with Apache License 2.0 5 votes vote down vote up
@Bean
public CronTriggerFactoryBean triggerRepositoryStatisticsCron(@Qualifier("repositoryStatisticsCron") JobDetail job) {
    CronTriggerFactoryBean trigger = new CronTriggerFactoryBean();
    trigger.setCronExpression(cron);
    trigger.setJobDetail(job);
    return trigger;
}
 
Example 14
Source File: SlaCheckerCronJob.java    From mojito with Apache License 2.0 5 votes vote down vote up
@Bean
public CronTriggerFactoryBean triggerSlaCheckerCronJob(@Qualifier("slaCheckerCron") JobDetail job) {
    CronTriggerFactoryBean trigger = new CronTriggerFactoryBean();
    trigger.setJobDetail(job);
    trigger.setCronExpression(incidentCheckCron);
    return trigger;
}