What I would like to do: If a user on my web application (tomcat, java) performs an action and 1 week passes before he performs it again, I would like to send him an email. For example, someone performs a "like" on jan 1, 2015 then performs another "like" on Jan 3, 2015, he will get sent an email on Jan 10, 2015 (provided he doesn't perform any more "like's" after Jan 3, 2015).
How to execute: Originally, I wanted to use a simple java.util.Timer Object. However, I couldn't find a way to reference different tasks for this Timer object. Every time a user performed said action, I would need to check if a task already exists for that user, if it did, I would reschedule it for 1 week from current time. But like I said, I couldn't reference tasks with the Timer Object.
So I looked into cron4j and Quartz. Cron4j seems simpler so I would like to use that. Cron4j.Scheduler allows for referencing tasks. As I understand, I would create one instance of the cron4j.Scheduler class for the entire web application and then schedule additional tasks as needed to this one instance of the Scheduler class. Is this correct? If so, How would I do this so that I can access an instance of the Scheduler class from a servlet later? (I thought of maybe setting an instance of the Scheduler as an attribute of the ServletContext. But, for this I would need to execute some servlet once per my web application. Is this how it would be done? If so, How do I specify that a servlet is to be executed once?)
I welcome any answers to my questions above or suggestions for different approaches for doing what I would like.
Thank you