开发者

send email "from database"

I'm thinking of possible ways, how trigger mail sending based on values - including time values - stored in database. One way, that I can think of is to use EJB @Timeout annotation, but I don't know how EJB stores these Timers before they are executed. Doesn't it consume too much memory? The other way can be to create a Thread, that will periodically check the database and if the va开发者_高级运维lues in db correspond, the email will be send. The next way might be to execute the java code from database with triggers. What are the advantages and disadvantages of these approach? Is there any other (better) approach?


If you need timed/scheduled events in your application it probably is the best to either use the EJB timer service (if you are indeed using EJB's) or use the Quartz scheduling service. I don't think database triggers would be the best solution in your case, as triggers normally only fire when certain events happen (ie an update or record insertion) and for as far as I can deduct from your question, you need to check the database every now and then and, depending on the values in the database, send emails, so not only check on an insert or update.

As I stated, when you already are using EJB's, I think the EJB timer service is the easiest solution to your problem. If you are using JEE5, check the JEE5 timer service tutorial and when you're using JEE6, check the JEE6 timer service tutorial. J2EE version 1.4 also has a timer service, but in that case I'd go for the Quartz scheduling service, as then that approach would probably easier. If you're not using any EJB's, you can always use the Quartz scheduling service.

With both the EJB Timer service and the Quartz scheduling service you can easily define a method and/or class that is called according to a by you definable schedule, for instance every hour, every minute or even every 5 seconds of each first monday of the month. This way you can let the scheduling service call a by you written method that checks the database and which then sends the emails if necessary. Both solutions are really easy to use and are really low on resource usage, so you won't have to be afraid of it consuming too much memory.

Kind regards

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜