Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how efficient are threadds for sending mails??  RSS feed

 
Amit Rogye
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'm writing a mailer daemon. My program will be querying a one column table for message ids. if there is a message id in that table then a master message table will be queried for that message id. From this master table we'll get to_id, from_id and body part of message. and By using JAVA mail API i'll send mail on to_id. and once mail is sent the record from one column table will be deleted.
Somebody gave me suggetion to use treading for this application, so that the performance will be improved. According to him my program will start 5 threads at a time and will do the job what i've explained above and it'll improve performance by 5 times. I'm not convinced with this concept. can anybody comment on this or suggest scallable solution???
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
99% of your time will be spent talking to the mail server. The mail server, in turn, spends all of that time doing I/O. Because of this, your mail throughput will be roughly proportional to the number of connections you open to the server, i.e. to the number of threads. Your colleague is right.
One remark, by the way: have you considered using JMS for this? What you describe looks exactly like the problem JMS was created to solve. Using JMS will also instantly solve all threading issues for you; to increase message throughput, just start up more message consumers.
- Peter
 
Amit Rogye
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Peter den Haan:
99% of your time will be spent talking to the mail server. The mail server, in turn, spends all of that time doing I/O. Because of this, your mail throughput will be roughly proportional to the number of connections you open to the server, i.e. to the number of threads. Your colleague is right.
One remark, by the way: have you considered using JMS for this? What you describe looks exactly like the problem JMS was created to solve. Using JMS will also instantly solve all threading issues for you; to increase message throughput, just start up more message consumers.
- Peter


Thanks for Reply. Can you tell how can i use JMS??? any sample or article will be helpful
/Amit
[ April 10, 2002: Message edited by: Amit Rogye ]
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sigh. Actually I have just developed a JMS-backed email queue. Unfortunately I'm not free to give you the code or the design detail.
In JMS, you can queue (among other things) any Serializable object. So all you have to do is queue an object that knows how to populate the JavaMail Message object, or maybe an object that carries the various ids you mentioned and that can be used to generate the e-mail.
It's all pretty straightforward and you don't need to use any JMS wizardry; if you rummage around on the net you're bound to find simple examples of queuing and dequeuing messages. It gives you ease of use, thread safety, and (if you use JMS's transactional capabilities) a guarantee that the e-mail will be sent out whatever happens.
You can use the JMS implementation built into the application server if your server has one, or an add-on implementation. OpenJMS is a decent open source implementation backed by a relational database.
- Peter
[ April 10, 2002: Message edited by: Peter den Haan ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!