问题
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.
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?
回答1:
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()
.
The plan is to add an injectable managed ScheduledExecutorService
for similar use cases.
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).
来源:https://stackoverflow.com/questions/58755470/programmatic-scheduling-what-is-the-best-approach