Jay Bose wrote:
If you want the Action to return immediately, and have the emails sent 
asynchronously,
then JMS is a definite option.
Another option is the JDK's Timer functionality
(http://java.sun.com/j2se/1.5.0/docs/api/java/util/TimerTask.html).

I recommend you use Java 5's concurrency package that supersedes TimerTask.:
http://java.sun.com/j2se/1.5.0/docs/guide/concurrency/overview.html

Setup a ThreadPoolExecutor with a Queue. When you need to send an email, submit it to the executor as a task to be scheduled later. When executed, the task looks up the mail session via jndi and sends the email. The settings for the pool and queue control how many can be scheduled and/or executed at once. Excluding the code that sends the email, that's only about 10 lines; but they need to be understood.

Compared to JMS, the disadvantage of this approach is that you have to manage the threads yourself (eg. shut them down when the container goes down), are responsible for all aspects of reliable delivery, you can't scale to multiple servers and you need to manage how the mail Session is available to your threads. But it's sufficient for many applications.

Hope that helps,
Jeromy Evans

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to