0

I would like schedule a task that gets executed periodically after the completion of task. Previously I used ScheduledExecutorService.scheduleWithFixedDelay but now in vertx I am thinking whether it may cause any issue since vertx already uses thread for event loop and worker verticles.

I checked Vertx.setPeriodic, but that just executes periodically without checking or waiting for the task to complete before scheduling other.

With all options explored currently I have a workaround where I use Vertx.setTimer to schedule the task and on completion I am calling Vertx.setTimer again inside the handler.

On high level the schedule task will query records from one table and update other table.

Anyone has any other better solution, please guide me.

Vertx version - 3.9.4

vel
  • 173
  • 9

1 Answers1

0

To my best knowledge ScheduledExecutorService.scheduleWithFixedDelay shouldn't cause any problems with Vert.x, and you can continue using it.

Your suggestion of setting timer in a callback is the better way of solving that, though.

Alexey Soshin
  • 16,718
  • 2
  • 31
  • 40
  • I decided to setup timer on callback. the periodic operation is getting records from one DB table, do calculation and insert into other table, is it good to do this operation in eventloop or worker thread? I am using vertx postgressql client. – vel Mar 30 '21 at 14:09
  • Blocking operations in general should be done with worker verticles. – Alexey Soshin Mar 30 '21 at 17:15
  • Thank you Alexey, Since I am using postgresqlclient which is asynchronous, is it safe to assume that event loop can be used? – vel Mar 30 '21 at 17:22
  • No, I don't think so. Although the client itself is not blocking, your code inside may still be. It's safer to use worker vertices instead. – Alexey Soshin Mar 30 '21 at 21:14
  • @Depop can I use vertx Sqlclient inside ScheduledExecutorService thread or should it be used inside vertx event loop? – vel Apr 28 '21 at 15:33
  • @Depop I have a question on event bus, can you please check this https://stackoverflow.com/q/67474368/14749640 – vel May 13 '21 at 02:02