Programmatic scheduling - what is the best approach?

≡放荡痞女 提交于 2020-04-18 07:10:29

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!