1

I am trying to schedule something than need to be ran every 200ms:

@Scheduled(every = "0.2s")

What's the recommended way to do it? Is there a good reason why @Scheduled doesn't support rate under the second?

1 Answer 1

3

Unfortunately, this is not supported. The idea is that @Scheduled is only used for cron-like tasks with an accuracy of seconds (note that the Cron standard is designed to work with an accuracy of minutes).

However, you can inject a managed Vertx instance and make use of Vertx.setPeriodic(). 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.

3
  • Thanks Martin :)
    – ia3andy
    Jan 7, 2020 at 15:01
  • btw maybe @Scheduled should not allow what it doesn't manage ? Current form is quite error-prone
    – Joel
    Jan 14, 2020 at 8:51
  • Yes, the validation could be improved. Feel free to file an issue here: github.com/quarkusio/quarkus/issues Jan 14, 2020 at 13:44

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.