Question

Could you please help me with reminder for calendar in Java that will be independent from the server. I mean, after restarting the server the action of reminder, for example, send an email, should be executed. I have already looked at this. But there said to use Timer. As i know, it depends on status of server. I also tried vs creating ejb with an annotation @Startup, but the problem, that TimedObject interface doesnt have any other fields for storing data that i want to present, only EJBTimeout(Timer t) method. Also using EJB it creates only one reminder for every user, but not for every appointment.

If i'm wrong, could you please correct me.

Was it helpful?

Solution

If you want to rely solely on an EJB facility, the you want to use EJB timers. EJB Timers are persistent across server restarts, and can be created dynamically. They rely on a Session Bean to take on the role of handling the timeout (in this case, sending the email).

The bright side of EJB timers is that they are persistent (unless optioned otherwise, you can make them not persistent), and that they survive server restarts. They will even fire off if the expire while the server is down when the server is restarted.

The dark side of EJB timers is that the persistent timers are LOST when the application is redeployed. So, if you change some logic or something unrelated that requires you to deploy the application again, then the timers are reset (since they are bound to the application).

This aspect can make them frustrating to use, as you'll need your own infrastructure to restart the timers that are lost when the server is redeployed. It's not difficult, basically you store a shadow of the EJB timer in to a database table of your own, and when your system deploys a start up event synchronizes this table with the existing timers that container knows about. Then you have your EJB timeout method delete the timer from the DB when the task is done.

It's not difficult, but it is annoying, and capturing the timer data is 85% of the whole "do something later" style of process in the first place. But it is what it is.

You can also look at Quartz, a popular scheduling framework that be fired up in the Servlet tier.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top