Class Builder

java.lang.Object
org.aoju.bus.cron.Builder

public final class Builder extends Object
定时任务工具类 此工具持有一个全局Scheduler,所有定时任务在同一个调度器中执行 setMatchSecond(boolean) 方法用于定义是否使用秒匹配模式,如果为true,则定时任务表达式中的第一位为秒,否则为分,默认是分
Since:
Java 17+
Version:
6.5.0
Author:
Kimi Liu
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Crontab配置文件
  • Method Summary

    Modifier and Type
    Method
    Description
    static Scheduler
     
    static List<Date>
    matchedDates(String patternStr, long start, long end, int count, boolean isMatchSecond)
    列举指定日期范围内所有匹配表达式的日期
    static List<Date>
    matchedDates(String patternStr, Date start, int count, boolean isMatchSecond)
    列举指定日期之后(到开始日期对应年年底)内所有匹配表达式的日期
    static List<Date>
    matchedDates(String patternStr, Date start, Date end, int count, boolean isMatchSecond)
    列举指定日期范围内所有匹配表达式的日期
    static List<Date>
    matchedDates(CronPattern pattern, long start, long end, int count, boolean isMatchSecond)
    列举指定日期范围内所有匹配表达式的日期
    static boolean
    remove(String schedulerId)
    移除任务
    static void
    重新启动定时任务 此方法会清除动态加载的任务,重新启动后,守护线程与否与之前保持一致
    static String
    schedule(String schedulingPattern, Runnable task)
    加入定时任务
    static String
    schedule(String id, String schedulingPattern, Task task)
    加入定时任务
    static String
    schedule(String schedulingPattern, Task task)
    加入定时任务
    static void
    schedule(org.aoju.bus.setting.magic.PopSetting cronSetting)
    批量加入配置文件中的定时任务
    static void
    setCronSetting(String cronSettingPath)
    自定义定时任务配置文件路径
    static void
    setCronSetting(org.aoju.bus.setting.magic.PopSetting cronSetting)
    自定义定时任务配置文件
    static void
    setMatchSecond(boolean isMatchSecond)
    设置是否支持秒匹配 此方法用于定义是否使用秒匹配模式,如果为true,则定时任务表达式中的第一位为秒,否则为分,默认是分
    static void
    开始,非守护线程模式
    static void
    start(boolean isDeamon)
    开始
    static void
    停止
    static void
    更新Task的执行时间规则

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Method Details

    • setCronSetting

      public static void setCronSetting(org.aoju.bus.setting.magic.PopSetting cronSetting)
      自定义定时任务配置文件
      Parameters:
      cronSetting - 定时任务配置文件
    • setCronSetting

      public static void setCronSetting(String cronSettingPath)
      自定义定时任务配置文件路径
      Parameters:
      cronSettingPath - 定时任务配置文件路径(相对绝对都可)
    • setMatchSecond

      public static void setMatchSecond(boolean isMatchSecond)
      设置是否支持秒匹配 此方法用于定义是否使用秒匹配模式,如果为true,则定时任务表达式中的第一位为秒,否则为分,默认是分
      Parameters:
      isMatchSecond - true支持,false不支持
    • schedule

      public static String schedule(String schedulingPattern, Task task)
      加入定时任务
      Parameters:
      schedulingPattern - 定时任务执行时间的crontab表达式
      task - 任务
      Returns:
      定时任务ID
    • schedule

      public static String schedule(String id, String schedulingPattern, Task task)
      加入定时任务
      Parameters:
      id - 定时任务ID
      schedulingPattern - 定时任务执行时间的crontab表达式
      task - 任务
      Returns:
      定时任务ID
    • schedule

      public static String schedule(String schedulingPattern, Runnable task)
      加入定时任务
      Parameters:
      schedulingPattern - 定时任务执行时间的crontab表达式
      task - 任务
      Returns:
      定时任务ID
    • schedule

      public static void schedule(org.aoju.bus.setting.magic.PopSetting cronSetting)
      批量加入配置文件中的定时任务
      Parameters:
      cronSetting - 定时任务设置文件
    • remove

      public static boolean remove(String schedulerId)
      移除任务
      Parameters:
      schedulerId - 任务ID
      Returns:
      是否移除成功,false表示未找到对应ID的任务
    • updatePattern

      public static void updatePattern(String id, CronPattern pattern)
      更新Task的执行时间规则
      Parameters:
      id - Task的ID
      pattern - CronPattern
    • getScheduler

      public static Scheduler getScheduler()
      Returns:
      获得Scheduler对象
    • start

      public static void start()
      开始,非守护线程模式
      See Also:
    • start

      public static void start(boolean isDeamon)
      开始
      Parameters:
      isDeamon - 是否以守护线程方式启动,如果为true,则在调用stop()方法后执行的定时任务立即结束,否则等待执行完毕才结束
    • restart

      public static void restart()
      重新启动定时任务 此方法会清除动态加载的任务,重新启动后,守护线程与否与之前保持一致
    • stop

      public static void stop()
      停止
    • matchedDates

      public static List<Date> matchedDates(String patternStr, Date start, int count, boolean isMatchSecond)
      列举指定日期之后(到开始日期对应年年底)内所有匹配表达式的日期
      Parameters:
      patternStr - 表达式字符串
      start - 起始时间
      count - 列举数量
      isMatchSecond - 是否匹配秒
      Returns:
      日期列表
    • matchedDates

      public static List<Date> matchedDates(String patternStr, Date start, Date end, int count, boolean isMatchSecond)
      列举指定日期范围内所有匹配表达式的日期
      Parameters:
      patternStr - 表达式字符串
      start - 起始时间
      end - 结束时间
      count - 列举数量
      isMatchSecond - 是否匹配秒
      Returns:
      日期列表
    • matchedDates

      public static List<Date> matchedDates(String patternStr, long start, long end, int count, boolean isMatchSecond)
      列举指定日期范围内所有匹配表达式的日期
      Parameters:
      patternStr - 表达式字符串
      start - 起始时间
      end - 结束时间
      count - 列举数量
      isMatchSecond - 是否匹配秒
      Returns:
      日期列表
    • matchedDates

      public static List<Date> matchedDates(CronPattern pattern, long start, long end, int count, boolean isMatchSecond)
      列举指定日期范围内所有匹配表达式的日期
      Parameters:
      pattern - 表达式
      start - 起始时间
      end - 结束时间
      count - 列举数量
      isMatchSecond - 是否匹配秒
      Returns:
      日期列表