我有以下弹簧石英配置。当我每分钟都有工作时,它工作正常。现在我需要解雇这个工作一定次数(特别是2次)。如何修改我的代码才能执行此操作?
@Bean
public SchedulerFactoryBean schedulerFactoryBeanJobOne() {
schedulerFactoryBean = new SchedulerFactoryBean();
schedulerFactoryBean.setAutoStartup(false);
schedulerFactoryBean.setTriggers(procesoJobOneTrigger().getObject());
schedulerFactoryBean.setJobDetails(procesJobOne().getObject());
schedulerFactoryBean.setJobFactory(springBeanJobFactory());
return schedulerFactoryBean;
}
@Bean
public SpringBeanJobFactory springBeanJobFactory() {
return new AutowiringSpringBeanJobFactory();
}
@Bean
public JobDetailFactoryBean procesJobOne() {
JobDetailFactoryBean jobDetailFactory = new JobDetailFactoryBean();
jobDetailFactory.setJobClass(JobOne.class);
jobDetailFactory.setGroup("quartz");
return jobDetailFactory;
}
@Bean
public CronTriggerFactoryBean procesoJobOneTrigger() {
CronTriggerFactoryBean cronTriggerFactoryBean = new CronTriggerFactoryBean();
cronTriggerFactoryBean.setJobDetail(procesJobOne().getObject());
// Runs every 60secs
cronTriggerFactoryBean.setCronExpression("0/60 * * * * ?");
cronTriggerFactoryBean.setGroup("quartz");
return cronTriggerFactoryBean;
}
答案 0 :(得分:2)
您的cron表达式是您无法提供作业运行的地方
# * * * * * command to execute
# │ │ │ │ │
# │ │ │ │ │
# │ │ │ │ └───── day of week (0 - 6) (0 to 6 are Sunday to Saturday)
# │ │ │ └────────── month (1 - 12)
# │ │ └─────────────── day of month (1 - 31)
# │ └──────────────────── hour (0 - 23)
# └───────────────────────── min (0 - 59)
你可以用这个:
# m h dom mon dow
0 14,15 * * *
你的工作将在14:00和15:00运行,即两次