Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

MultiThreading in Java Mail and Shared Session

843834Dec 3 2009 — edited Dec 9 2009
I am in a process of developing a Java Mail Application.
The requirement is to actually send 10 different mails to 10 different email addresses with 10 different attachments(reports). The number of mails sent can be more than 10.

I am actually thinking of creating 10 different Thread instances for this. i.e. one thread - one mail - one attachment.
I hope above is clear.

So I would imagine of creating individual session for each thread. i.e. if one mail has to be sent, one thread starts,creates a session, sends mail and closes the session.So in my case 10 different sessions can be created.
If even one session fails , the other sessions conitnue their work and other mails are still sent is not stopped.

I know that shared session can be created. So other option can be passing one single session to 10 different threads so that all threads use the same session. But in this case if the session fails , no mail would be sent.

I do not want to send mails to other addresses even if any one fails at a given time.

Please can you provide any suggestions?
I am totally new to Java Mail and have no idea how many mails/sessions can be created with SMTP. Also is it feasible to create a new session for every mail?
The main point is that Error should not stop the process of sending mails.

Thanks a lot in advance.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 6 2010
Added on Dec 3 2009
10 comments
3,524 views