Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

How to send out email asynchronously in action class?

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using struts 2. I have a page that when user click forgot password button, in the action class, it finds user's password and send out email. I am using javax.mail.
I want to know how to let the page reponse right way and do sending out email at the backgroud.

Thanks.
 
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While it's not hard to start a new thread that does this, what are you really gaining by that for just a single address? The JavaMail call to send that mail should return quickly. Or are you trying to guard against a possibly unavailable mail server?
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Personally, I'd have a job that sends emails. Like Ulf says, though, if it's a "rare" event, you can just do it inside the action.

With S2's Spring integration it's fairly straight-forward to have a Quartz job.
 
lao zhang
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dittmer: Is any performance issue if starting a new thread to send out email?
 
Ulf Dittmer
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What, exactly, do you mean by "performance issue"? Of course, starting a new thread takes CPU cycles. Whether that makes any difference at all to the overall application depends on how often you plan to do that; users forgetting a password should be a comparatively rare occurrence, so I wouldn't worry.
 
Popeye has his spinach. I have this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
    Bookmark Topic Watch Topic
  • New Topic