簡體   English   中英

每小時安排一次工作,介於50到60分鍾之間

[英]Schedule a job every hour between 50 and 60 minutes once

我正在嘗試在春季使用@Schedule,我想知道是否可以使用cron在50分鍾至59分鍾之間每小時運行一次,例如:它將運行:13:58,14:52 ,15:57 16:50等...

謝謝

請參閱以下示例:

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''.

怎么樣

0 55 * 1/1 * ? *

cronmaker.com一直是我生成cron表達式的好資源。

我認為@Scheduled僅接受靜態cron表達式,並且您不得在表達式中使用SpEL。

但是,您可以實現自定義Trigger 通過使用ScheduledTaskRegistrar.addTriggerTask@Configuration類中實現SchedulingConfigurer ,可以與要執行的任務一起注冊此觸發器。

您可以使用Spring的RandomValuePropertySource

試試吧:

@Scheduled(cron='0 ${random.int[0,9]} * 1/1 * *')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM