/** * Creates a new schedule for the given cron expression. The cron expression is not verified immediately, * but invalid expressions will cause {@link SchedulerService#scheduleJobWithGeneratedId(JobConfig)} to fail. * * @param cronExpression the cron expression to use for the schedule * @param timeZone the time zone within which to apply the rules of the cron expression; may be {@code null} * to use a default time zone that is appropriate for the application * @return a schedule for running jobs when the given cron expression is satisfied */ public static Schedule forCronExpression(String cronExpression, @Nullable TimeZone timeZone) { return new Schedule(Type.CRON_EXPRESSION, null, new CronScheduleInfo(cronExpression, timeZone)); }
/** * Creates a new schedule that will run periodically with the given interval. * <p> * <strong>WARNING</strong>: Implementations are not required to honour the time interval at millisecond * precision. The actual resolution that is permitted is implementation-defined. Implementations should * round the requested interval up and persist the rounded value so that the interval reported by * later calls to {@link Schedule#getIntervalScheduleInfo()} will be consistent with the behaviour that the * scheduler actually provides. * </p> * * @param intervalInMillis the minimum time interval (in milliseconds) between runs. If the * value {@code 0L} is specified, then the job will not repeat (this is equivalent to using * {@link #runOnce(Date) runOnce(firstRunTime)}). Negative values are not permitted. * @param firstRunTime when the job should run for the first time; may be {@code null} to indicate that * the job should run as soon as possible * @return a schedule for running once at the given time */ public static Schedule forInterval(long intervalInMillis, @Nullable Date firstRunTime) { return new Schedule(Type.INTERVAL, new IntervalScheduleInfo(firstRunTime, intervalInMillis), null); }