程序化调度 - 最好的方法是什么? [英] Programmatic scheduling - what is the best approach?
问题描述
我需要根据一些配置数据启动多个独立的周期性任务 - 总数事先未知.比如我想查看不同目录下不同间隔、不同参数的内容,这里的列表和参数是从配置中读取的.
I need to start multiple independent periodic tasks based on some configuration data - the total number is not known upfront. For example, I would like to check the content of different directories with different intervals and different parameters, where the list and parameters are read from the configuration.
在我看来,quarkus-scheduler 只能调度固定的、预先已知的方法.动态/以编程方式进行调度的最佳方法是什么?vertx.setPeriodic
是正确的方法还是我应该以某种方式访问 Quartz?
It seems to me that the quarkus-scheduler can schedule just the fixed, upfront-known methods. What is the best approach to do the scheduling dynamically/programmatically? Is vertx.setPeriodic
the right approach or should I somehow access Quartz?
推荐答案
是的,您可以注入托管 Vertx
实例并使用 Vertx.setPeriodic()
或Vertx.setTimer()
(一次性定时器).但请记住,处理程序是在事件循环线程上执行的,因此代码不应阻塞.如果您确实需要执行一些阻塞代码,请查看 Vertx.executeBlocking()
.
Yes, you can inject a managed Vertx
instance and make use of Vertx.setPeriodic()
or Vertx.setTimer()
(one-shot timer). But keep in mind that the handler is executed on an event loop thread and so the code should not block. If you really need to execute some blocking code then look at Vertx.executeBlocking()
.
计划是为类似的用例添加一个可注入的托管 ScheduledExecutorService
.
The plan is to add an injectable managed ScheduledExecutorService
for similar use cases.
还有https://github.com/quarkusio/quarkus/issues/7246 - 这将允许您利用 Quartz API(当使用 quarkus-quartz
扩展时).
There is also https://github.com/quarkusio/quarkus/issues/7246 - this would allow you to leverage the Quartz API (when using the quarkus-quartz
extension).
这篇关于程序化调度 - 最好的方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!