How to set a persistent timer for vertx which wont be lost if the server is restarted?

Viewed 70

how do I set a function to run after 72 hours, the server maybe restarted during this 72 hours but the timer should resume after the restart. Is there any timers in vertx or java to make this possible.

1 Answers

a.) Use a database

  1. store last execution timestamp
  2. periodically check if the timestamp is older than 72 hours
  3. if yes, execute your task and update the timestamp

b.) Run vertx in clustered mode

  • save last execution timestamp in a sharedmap
  • this is accessible by each instance to see when the task needs to be executed
  • when one instance is restarted, the shared map is still not lost
  • to ensure single execution, use a distributed lock
Related