gpt4 book ai didi

java - quartz 固定次数

转载 作者:行者123 更新时间:2023-11-30 08:50:17 26 4
gpt4 key购买 nike

我有以下 Spring quartz 配置。当我每分钟都被解雇时,它工作得很好。现在我需要将这个工作解雇固定次数(特别是 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;
}

最佳答案

您的 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 运行,即两次

关于java - quartz 固定次数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31029617/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com