Meaningless Drivel is fun!
The moose likes Threads and Synchronization and the fly likes Sending multiple mails through threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Sending multiple mails through threads" Watch "Sending multiple mails through threads" New topic

Sending multiple mails through threads

Jaydeep Deshmukh
Ranch Hand

Joined: Sep 10, 2002
Posts: 31
Hi All,

In our current application, the emails are being sent out to the relevant users in a procedural after another.

Now this needs to be changed to doing it using threads. I have two questions here.
1. Would this be as straight forward as spawning a thread per email to be sent? Would there be any exceptional scenarios?
2. What if any of the mails fail to go out and throw and exception. How do I keep tabs as to from which thread this exception occured?

Thanks in advance
Ken Blair
Ranch Hand

Joined: Jul 15, 2003
Posts: 1078
Sounds like the kind of thing that would make use of an ExecutorService. You probably don't to waste resources creating a new thread for every single mail to be sent. By using an ExecutorService or a similar construct you can put the burden of creating and managing threads on another object and instead pass it a Runnable or Callable and get a Future back if you need to know the result.
I agree. Here's the link:
subject: Sending multiple mails through threads
jQuery in Action, 3rd edition