Spring boot Spring调度程序不会在循环后停止,而是在停止并重新触发之前运行1分钟 @Slf4j @组成部分 公共类调度程序{ @自动连线 私人缺席; @已计划(cron=“***/5****”) 私有void testCron(){ 字符串hour=“01”; List object1List=new ArrayList(abService.getListOfobject(小时)); for(Object1 Object1:object1List){ System.out.println(“对象”+object1); } log.info(“Cron finish run at”+新时间戳(System.currentTimeMillis()); } }
我是这个调度程序spring的新手,我发现在for循环之后很难让它停止。 在object1List(即3对象)中获取对象列表后,它进入循环3次(正确)。但是,在循环3次后停止cron,它将继续循环1分钟Spring boot Spring调度程序不会在循环后停止,而是在停止并重新触发之前运行1分钟 @Slf4j @组成部分 公共类调度程序{ @自动连线 私人缺席; @已计划(cron=“***/5****”) 私有void testCron(){ 字符串hour=“01”; List object1List=new ArrayList(abService.getListOfobject(小时)); for(Object1 Object1:object1List){ System.out.println(“对象”+object1); } log.info(“Cron finish run at”+新时间戳(System.currentTimeMillis()); } },spring-boot,cron,scheduler,spring-scheduled,Spring Boot,Cron,Scheduler,Spring Scheduled,我是这个调度程序spring的新手,我发现在for循环之后很难让它停止。 在object1List(即3对象)中获取对象列表后,它进入循环3次(正确)。但是,在循环3次后停止cron,它将继续循环1分钟 我需要做的是确保cron每5分钟运行一次,但在完成任务后停止,而不是将同一任务循环1分钟您应该在项目中添加@EnableScheduling Anotion 你的cron每秒都在运行。(您的cron秒值=*) 如果您只想在五分钟内工作一次,请尝试:@Scheduled(cron=“0*/5***
我需要做的是确保cron每5分钟运行一次,但在完成任务后停止,而不是将同一任务循环1分钟您应该在项目中添加@EnableScheduling Anotion 你的cron每秒都在运行。(您的cron秒值=*) 如果您只想在五分钟内工作一次,请尝试:
@Scheduled(cron=“0*/5****”
cron格式:
@Slf4j
@Component
public class ABScheduler {
@Autowired
private ABService abService;
@Scheduled(cron="* */5 * * * *")
private void testCron(){
String hour = "01";
List<Object1> object1List = new ArrayList<>(abService.getListOfobject(hour));
for(Object1 object1: object1List ){
System.out.println("object " +object1);
}
log.info("Cron finish run at "+ new Timestamp(System.currentTimeMillis()) );
}
}
资源:
┌───────────── second (0-59)
│ ┌───────────── minute (0 - 59)
│ │ ┌───────────── hour (0 - 23)
│ │ │ ┌───────────── day of the month (1 - 31)
│ │ │ │ ┌───────────── month (1 - 12) (or JAN-DEC)
│ │ │ │ │ ┌───────────── day of the week (0 - 7)
│ │ │ │ │ │ (0 or 7 is Sunday, or MON-SUN)
│ │ │ │ │ │
* * * * * *