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?
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.
@Scheduled
should not allow what it doesn't manage ? Current form is quite error-prone