This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
In our current application, the emails are being sent out to the relevant users in a procedural manner...one 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?
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.