Eric,
You can use a simple Consumer/Producer pattern here.
See the java.util.Queue classes. What I have done in a similar situation
is create a single Queue, multiple consumer threads all blocking on the
same queue. A user action puts something in the queue, and one of the
thread comes out of the blocked state to de-queue it and process the
request (which in your case would be sending the email).
Padam
On 22/07/10 10:28 AM, Eric P wrote:
Hi all,
In my Tomcat app I'm looking for a good (or commonly used) method for
firing off an asynchronous task. For example, a user registers for an
account, and an a task to send a verification email to the user is
triggered w/o delaying the response to the user (i.e., task happens in
the background).
I'm somewhat aware that JMS could be used for this and is part of most
J2E environments, but I'd like to see if there's some way to pull this
off w/vanilla Tomcat.
I had a couple ideas that would probably work, but I'd like to see how
others have solved this problem.
One idea would be to insert a record into a database table that
signifies an email should be sent to the user. This table could be
regularly checked by a scheduled job (e.g., a TimerTask) that runs
every minute in the background.
Another (maybe not so good) idea would be to leverage perhaps a
session or request attribute listener that would check for a certain
attribute being added to a session or requests. Then if a 'send
email' attribute comes through, the listener could process an email.
This seems like a bad idea though as I believe the listener event
class would be triggered incessantly any time attributes are
added/removed when in fact I'm only actually interested in the 'send
email' attribute.
Anyway, I'm open to all ideas and appreciate you indulging me this far.
Eric P.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org