This is very useful for me slightly different circumstance. +1
On Thu, Jul 22, 2010 at 10:17 AM, Pid <p...@pidster.com> wrote: > On 22/07/2010 05:58, 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. > > You didn't say which version of Tomcat and JVM you're using, so I'll > assume the latest - 6.0.28 and 1.6. > > Have a look at Executors.class in java.util.concurrent. You can > start/stop an ExecutorService in the init/destroy methods of your > Servlet, submit a Runnable to the ExecutorService representing the > job(s) you want to execute. > > > p > > > Eric P. > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org > > For additional commands, e-mail: users-h...@tomcat.apache.org > > > > >