Java 在50到60分钟之间每小时安排一次作业
我正在尝试在spring中使用@Schedule,我想知道是否有一个选项可以使用cron在50到59分钟之间每小时运行一次,例如: 它将运行:13:58、14:52、15:57、16:50等 谢谢怎么样Java 在50到60分钟之间每小时安排一次作业,java,spring,cron,quartz-scheduler,Java,Spring,Cron,Quartz Scheduler,我正在尝试在spring中使用@Schedule,我想知道是否有一个选项可以使用cron在50到59分钟之间每小时运行一次,例如: 它将运行:13:58、14:52、15:57、16:50等 谢谢怎么样 0 55 * 1/1 * ? * 对于生成cron表达式来说,始终是一个很好的资源 我认为@Scheduled只接受静态cron表达式,不能在表达式中使用SpEL 但是,您可以实现自定义。与待执行任务一起,可以通过在@Configuration类中使用来注册此触发器。您可以使用Spring中的
0 55 * 1/1 * ? *
对于生成cron表达式来说,始终是一个很好的资源
我认为@Scheduled
只接受静态cron表达式,不能在表达式中使用SpEL
但是,您可以实现自定义。与待执行任务一起,可以通过在
@Configuration
类中使用来注册此触发器。您可以使用Spring中的RandomValuePropertySource
试试看:
@Scheduled(cron='0 ${random.int[0,9]} * 1/1 * *')
请参见此示例:
0 50-59/1 * * *
从crontab手册页第5节:
field allowed values
----- --------------
minute 0-59
hour 0-23
day of month 1-31
month 1-12 (or names, see below)
day of week 0-7 (0 or 7 is Sun, or use names)
A field may be an asterisk (*), which always stands for ``first-last''.
Ranges of numbers are allowed. Ranges are two numbers separated with a hyphen. The specified range is inclusive. For example, 8-11 for an
``hours'' entry specifies execution at hours 8, 9, 10 and 11.
Lists are allowed. A list is a set of numbers (or ranges) separated by commas. Examples: ``1,2,5,9'', ``0-4,8-12''.
你写的表达式会在每小时55分钟触发,这不是我要找的for@GalSosin,查看我对
SchedulingConfigurer
@galsos的编辑。您是否尝试使用SchedulingConfigurer
,或者在这个问题上取得了任何其他进展?没有尝试that@GalSosin您是否同时尝试实施了SchedulingConfigurer
,13:51,13:52,13:53,13:54,13:55…我不确定cron格式是否可以实现为随机的。是的,我也是。这就是我想知道的