Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

About sending Email using Servlet  RSS feed

 
Ken Shamrock
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I tried the sample email sending Servlet comes with Tomcat 4.0, I found that everytime it will takes around 3-4 seconds to send an email, is it normal? If so, do you have any method to improve the performance? Thanks.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thats not really surprising, it is probably network delays since the Java involved is simple. I like to hand off mail jobs to a separate Thread - that way if the mail server is temporarily not talking, you can try later.
Bill
 
Ken Shamrock
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.
Where I can find a sample code of using Threads inside Servlet? Thanks
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using a Thread to perform some task in cooperation with a servlet is a little tricky but do-able if you remember that the servlet can be handling multiple requests. In this case you could create a class to represent a single email.
A "singleton style" Runnable class to handle sending the data to a mail server would hold a vector of email objects. Your servlet would create the email object, add it to the vector and finish the response. The mailing class Thread would sleep most of the time but wake up every now and then to see if there was any mail to send.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!