Java 按设置的重复间隔安排消息
我在Spring Boot/JPA域中有以下任务:Java 按设置的重复间隔安排消息,java,spring,spring-boot,quartz-scheduler,Java,Spring,Spring Boot,Quartz Scheduler,我在Spring Boot/JPA域中有以下任务: id: 1, task: GET:http://example.com/file.zip, schedule: every-minute id: 2, task: DELETE:/some/path, schedule: every-5-minutes id: 2, task: TOUCH:/some/path, schedule: every-1-hour 我有一个名为taskHandlerService的spring服务,它能够处理上述任
id: 1, task: GET:http://example.com/file.zip, schedule: every-minute
id: 2, task: DELETE:/some/path, schedule: every-5-minutes
id: 2, task: TOUCH:/some/path, schedule: every-1-hour
我有一个名为taskHandlerService
的spring服务,它能够处理上述任务,
但是我一直想知道如何安排它们,以便消息以指定的间隔到达taskHandlerService
任务列表经常更改,因此这些作业不会长时间运行
我在这里想到的一种简单方法是创建多个Quartz作业,列表中的每个任务一个,然后该作业将负责调用taskHandlerService
上的方法,并将消息作为参数
有没有更好的方法来解决这个问题
更新:经过一点搜索,延迟队列似乎是更好的方法。但不确定如何将Qaurtz Cron调度表达式转换为该队列。您可以使用
@Scheduled
注释标记方法,Spring将关心如何创建计时器等
您可以使用
@Scheduled
注释标记方法,Spring将关心如何创建计时器等
您可以在方法中使用这些注释:
@Scheduled(cron = "0 */1 * ? * *") // for the first method
@Scheduled(cron = "0 */5 * ? * *") //Second method
@Scheduled(cron = "0 0 * ? * *") // third method
有关更多信息,您可以查看一个示例,您可以使用这些注释来说明您的方法:
@Scheduled(cron = "0 */1 * ? * *") // for the first method
@Scheduled(cron = "0 */5 * ? * *") //Second method
@Scheduled(cron = "0 0 * ? * *") // third method
有关详细信息,您可以查看一个示例消息列表存储在表中且不是静态的。消息列表存储在表中且不是静态的。消息列表存储在表中且不是静态的。消息列表存储在表中且不是静态的。