The moose likes Threads and Synchronization and the fly likes how efficient are threadds for sending mails?? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "how efficient are threadds for sending mails??" Watch "how efficient are threadds for sending mails??" New topic
Author

how efficient are threadds for sending mails??

Amit Rogye
Greenhorn

Joined: Sep 09, 2001
Posts: 5
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

Joined: Apr 20, 2000
Posts: 3252
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

Joined: Sep 09, 2001
Posts: 5
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

Joined: Apr 20, 2000
Posts: 3252
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 ]
 
IntelliJ Java IDE
 
subject: how efficient are threadds for sending mails??
 
Threads others viewed
What effects by using a lot of foreign keys?
Hibernate one-to-many weirdness...
OneToOne shared PK isn't setting key in related table during insertion
retrieve values from hashmap in java
Question about the type of JoinColumn.
developer file tools