quartz-schedule SimpleScheduleBuilder

本文详细介绍了Quartz定时任务的各种配置方法,包括但不限于按分钟、秒、小时重复执行的任务设置,以及如何设置任务的执行次数和间隔时间。此外,还讲解了如何处理任务错过执行的情况。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

方法名称说明
repeatMinutelyForever()设置为永远重复,间隔时间为1分钟
repeatMinutelyForever(int minutes)设置为永远重复,间隔时间为参数设置的分钟数,例如,minutes=3,则每三分钟调度一次
repeatSecondlyForever()设置为永远重复,间隔时间为1秒钟
repeatSecondlyForever(int seconds)设置为永远重复,间隔时间为参数设置的秒数
repeatHourlyForever()设置为永远重复,间隔时间为1小时
repeatHourlyForever(int hours)设置为永远重复,间隔时间为设置的小时数
repeatMinutelyForTotalCount(int count)设置参数为指定重复的次数,间隔实际为1分钟,例如,count=3,则每分钟执行一次,重复三次
repeatMinutelyForTotalCount(int count, int minutes)设置间隔时间为minutes分钟,执行次数为count
repeatSecondlyForTotalCount(int count)设置参数为指定重复的次数,间隔时间为1秒钟
repeatSecondlyForTotalCount(int count, int seconds)设置间隔时间为seconds秒,执行次数为count
repeatHourlyForTotalCount(int count)设置参数为指定重复的次数,间隔时间为1小时
repeatHourlyForTotalCount(int count, int hours)设置间隔时间为hours小时,执行次数为count
withIntervalInMilliseconds(long intervalInMillis)设置重复间隔为intervalInMillis毫秒,当不设置重复次数时候默认只执行一次。例如:SimpleScheduleBuilder.simpleSchedule().withIntervalInMilliseconds(1000L).withRepeatCount(3);--设置重复间隔为1000毫秒,重复次数为(3+1)次。SimpleScheduleBuilder.simpleSchedule().withIntervalInMilliseconds(1000L); --设置重复间隔为1000毫秒,重复次数为默认值1次
withIntervalInSeconds(int intervalInSeconds)设置重复间隔为intervalInSeconds秒,当不设置重复次数时候默认只执行一次。例如:SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(4).withRepeatCount(2);--设置重复间隔为4秒,重复次数为(2+1)次。SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(4);--设置重复次数间隔为4秒,重复次数为默认值1次
withIntervalInMinutes(int intervalInMinutes)设置重复间隔为intervalInMinutes分钟,当不设置重复次数时候默认只执行一次。例如:SimpleScheduleBuilder.simpleSchedule().withIntervalInMinutes(1).withRepeatCount(2);--设置重复间隔为1分钟,重复次数为(2+1)次。SimpleScheduleBuilder.simpleSchedule().withIntervalInMinutes(1);--设置重复次数间隔为1分钟,重复次数为默认值1次
withIntervalInHours(int intervalInHours)设置重复间隔为intervalInHours小时,当不设置重复次数时候默认只执行一次。例如:SimpleScheduleBuilder.simpleSchedule().withIntervalInHours(1).withRepeatCount(2);--设置重复间隔为1小时,重复次数为(2+1)次。SimpleScheduleBuilder.simpleSchedule().withIntervalInHours(1);--设置重复次数间隔为1小时,重复次数为默认值1次
withRepeatCount(int triggerRepeatCount)设置重复次数为triggerRepeatCount次,配合withIntervalInXxx使用(不能单独使用,不设置间隔时间时候报错);例如:SimpleScheduleBuilder.simpleSchedule().withRepeatCount(5).withIntervalInMinutes(1);--设置重复次数为(5+1)次,重复间隔时间为1分钟。SimpleScheduleBuilder.simpleSchedule().withRepeatCount(5);--未设置间隔时间,报错
repeatForever()设置为一直重复,配合withIntervalInXxx使用(不能单独使用,不设置间隔时间时候报错);例如:SimpleScheduleBuilder.simpleSchedule().repeatForever().withIntervalInMinutes(1);--设置为一直重复,重复间隔时间为1分钟。SimpleScheduleBuilder.simpleSchedule().repeatForever();--未设置间隔时间,报错
withMisfireHandlingInstructionIgnoreMisfires()始终是到原来的结束时间就结束。重新计算执行次数,misfire后当前的执行立即触发。例如,结束时间是18:00,执行次数是5次,17:45时出现misfire,17:50时候恢复,
withMisfireHandlingInstructionFireNow()只要发生misfire就会延迟结束时间。例如,19:19:40 执行完之后发生misfire,19:20:03才开始恢复,最近的一次执行应该在19:20:00,相差3秒,这就是延迟的时间差。
withMisfireHandlingInstructionNextWithExistingCount()无论是否发生misfire,到原来的结束时间就结束。
withMisfireHandlingInstructionNextWithRemainingCount()无论是否发生misfire,到原来的结束时间就结束。
withMisfireHandlingInstructionNowWithExistingCount()只要发生misfire,重新执行(初始次数 + 重复执行次数)之和
withMisfireHandlingInstructionNowWithRemainingCount()无论发生misfire与否,执行次数一定是之前设定的。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值