user3414980
user3414980

Reputation: 29

J2EE sending scheduled emails using JMS queue

I need to create J2EE application, that uses JMS queue to asynchronously send emails, that can be scheduled to be sent later.

I already created bean, that sends message with email data and MessageDriven bean, which listens for those messages and sends email, onMessage. Right now, I have no idea how to implement scheduling. I was thinking of some TimerTasks like I did in Java before, but I'm not sure if I can do that in J2EE. Any advices how to do this?

Upvotes: 0

Views: 899

Answers (3)

Alexander Rühl
Alexander Rühl

Reputation: 6939

Since Java EE 6 there is no need to use JMS just for asynchronism, you can instead use @Asynchronous on your EJB. See Adam Biens post on that topic for an example.

Concerning scheduling, crea1 pointed to the right tool for it. Alternatively, you can use a 3rd party framework, like the Quarz Framework, which we use in our application, since it is more sophisticated.

Upvotes: 0

Leos Literak
Leos Literak

Reputation: 9474

Why do you need scheduling at all? Do you set concrete time when the email must be sent? If your requirement is simply to send email later, you do not need nothing else than JMS queue and some bean to read it. You can tune number of threads for this bean as well.

If you want to send the email on concrete date, then it is possible to set JMS attribute for delivery time and configure the bean to read the messages that matches a condition. See message selectors in Message javadoc.

Upvotes: 0

crea1
crea1

Reputation: 12517

Have you looked into the @Schedules and @Schedule annotations? You can use it to set up cron-like schedules.

http://docs.oracle.com/javaee/6/api/javax/ejb/Schedule.html

Upvotes: 1

Related Questions