quartz-schedule SimpleScheduleBuilder

方法名称说明
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与否,执行次数一定是之前设定的。
  • 5
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Quartz 是一个开源的作业调度框架,可以用来调度执行 Java 任务。下面是一个简单的 Quartz 配置示例: 1. 首先,需要在项目中引入 Quartz 的依赖包,例如: ```xml <dependency> <groupId>org.quartz-scheduler</groupId> <artifactId>quartz</artifactId> <version>2.3.2</version> </dependency> ``` 2. 然后,在项目中创建一个 properties 文件,例如 quartz.properties,用来配置 Quartz 的一些参数,例如: ```properties org.quartz.scheduler.instanceName = MyScheduler org.quartz.scheduler.instanceId = AUTO org.quartz.threadPool.threadCount = 5 org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.StdJDBCDelegate org.quartz.jobStore.dataSource = myDS org.quartz.jobStore.tablePrefix = QRTZ_ org.quartz.dataSource.myDS.driver = com.mysql.jdbc.Driver org.quartz.dataSource.myDS.URL = jdbc:mysql://localhost:3306/quartz org.quartz.dataSource.myDS.user = root org.quartz.dataSource.myDS.password = root org.quartz.dataSource.myDS.maxConnections = 10 ``` 3. 接下来,需要在代码中创建一个 Scheduler 对象,并启动它,例如: ```java // 创建调度器 Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler(); // 启动调度器 scheduler.start(); ``` 4. 最后,需要创建一个 JobDetail 对象和一个 Trigger 对象,并将它们关联到 Scheduler 中,例如: ```java // 创建 JobDetail 对象 JobDetail jobDetail = JobBuilder.newJob(MyJob.class) .withIdentity("myJob", "myGroup") .build(); // 创建 Trigger 对象 Trigger trigger = TriggerBuilder.newTrigger() .withIdentity("myTrigger", "myGroup") .withSchedule(SimpleScheduleBuilder.repeatSecondlyForever(10)) .build(); // 将 JobDetail 和 Trigger 关联到 Scheduler 中 scheduler.scheduleJob(jobDetail, trigger); ``` 这样,当调度器启动后,就会按照 Trigger 中定义的调度规则,定时执行 MyJob 类中的任务。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值