• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

How to send Java Mail to recipients based on different recipients ?

 
Ranch Hand
Posts: 523
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I would like to seek opinions how to make my code more 'beautiful'.

Currently, I have 2 types of Recipients for sending email -  user when registered and parents when they sent the enquiry form.

So, depending on which servlet was invoked.  If it is user then a mail will be sent to them and same applies to the parents'.

Now, only thing is with the code which is in my sendMail class :



How do I incorporate the method to make it known to send mail to the user or the parents' ?

The code now contains 2 types of recipients so I think this code is not 'beautiful'.

Hope someone can guide me how to improve the code....

Many thanks.



 
tangara goh
Ranch Hand
Posts: 523
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have further added



But, now I wonder if the two servlets are invoked a the same time then I do not want the mail to just send out to one user, how do I make the code work to check if the 2 servlets are invoked at the same time ?

Hope someone can share with me some tips.

Thanks.

 
Saloon Keeper
Posts: 5588
144
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the code is thread-safe (which means protecting access to shared mutable data) then it doesn't matter if the code is run concurrently for multiple users. Not using instance variables (at least none that change over time) in your servlet and filter would be a good start.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!