I am working on a Java / Spring web application. The application issues licenses on demand. Each license has an expiry date. Licenses can be renewed by the admin. I want to send an email notification or perform some operation 90, 45, 30, x, y, z no. of days before the license expiry. The email notification to be sent exactly before those number of days (not required to be accurate to minutes) is a contractual obligation and must be sent until the license is renewed.

I'm thinking of following ways to implement this.

  • Implement a Spring Scheduler that runs once every day and checks for licensing expiring after current day + x days and send out an email notification. However, I'm concerned about the job not running on a specific day like application maintenance etc. For eg, 45th-day email can be missed as the job did not run on 45th day. Seems like error prone. To avoid that, Set a 90, 45, 30, x, y, z columns in another table against each license, but for the 2nd renewal, this will be a problem. To avoid that, keep track of the days the scheduler is run so if the scheduler does not run on any day or does not finish successfully, re-run it manually.

This is a stateless web app running multiple instances. Should I be implementing these sort of operations as a separate batch job or within the web application as a scheduler?

Will appreciate any ideas or pointers to resources.

  • If these notifications are critical to your business, better have'em running apart from the web. As Spring Batch into another war or as a system servíce. Maintenance over the web app should not affect (IMO)
    – Laiv
    Sep 26, 2016 at 6:13

2 Answers 2


We have implemented similar behaviour with RabbitMQ delayed messages.

The only thing you had to make sure was working was the message routing, because if a delayed message could not be routed at scheduled time it would be discarded (as per AMQP).

Other than that the implementation is really straightforward and simple, you set up a publisher and consumer pair just like you would when using regular RabbitMQ messages.

In your case you would:

  1. take the expiration date of an item,
  2. subtract the number of days when a notification shall be sent for that specific item,
  3. convert the subtracted date from step 2 to timestamp,
  4. subtract timestamp of current date from tinestamp from the step 3,
  5. use timestamp from step 4 as a number of seconds for delay.

Suggest you take a look at the Quartz scheduler rather than waste time reinventing the wheel. I've had great success with the .Net version of it. http://www.quartz-scheduler.org is for the Java version.

Your Answer

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

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