0

Let's say I have a customer who's account is set to expire on a given date. I have a task coded that will decommission the service but I'm not sure how to kick off the task exactly on the specified date.

I'm looking for a way to schedule a one-time future task with the following requirements:

  • The task must be kicked off once, at exactly the time specified.
  • The scheduling mechanism should be persistent. If the server goes down, the list of tasks should recover and kick off any that elapsed during the outage.

Since I'm using Java, Quartz seems like a reasonable option, but I've only used it for cron-based scheduling. I'm not sure if it could used for something like this or what the best practices are - especially with the persistence portion.

Does Spring have anything in this area?

Tyler Murry
  • 2,705
  • 3
  • 29
  • 46

1 Answers1

0

The Java Timer class, combined with a custom DeactivateCustomerTask would be be enough for all but the persistence through a power failure issue.

For persistence, you could keep a List which was serialized to the HDD and then read back again at power up. But you must already have the customer data saved to the disk, so it makes more sense to simply recreate the List from scratch by scanning that database. Afterall, an account may have expired while the server was offline and you will need to handle that case specially at power up.

You probably already realize this, but DeactivateCustomerTask will need to make sure the Customer has not renewed after it was created; and the renewal methods will need to make sure that a DeactivateCustomerTask is not concurrently executing.

Teto
  • 475
  • 2
  • 10