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?
Thanks in advance Jaydeep
posted 10 years ago
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.