Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Trying to create a threaded pool in JavaMail to deal with bulk mailing  RSS feed

 
Iain Emsley
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm working on a bulk mailer as part of scheduling system to handle any size of group and one of the bottle necks that we've found is fact the that each email needs to wait until the previous one is sent which in turn means the entire application freezes whilst mail is being sent (which given we have lists of over a thousand members means it could be a while) so I'm trying to implement some sort of basic threaded mail queue. I thought that I had the basics but nothing is being sent from the queue though the logging suggests that items are being added to the pool LinkedList entity

As it is my first shot at threading, I've probably misunderstood something or just plain missed it out but would appreciate pointers in the right direction.
 
Mark Vedder
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Implmenting your own thread pool from scratch is tricky. And from a quick look through your code, it looks like you are heading down the wrong path.

I would suggest looking at the java.util.concurrent Package (added in Java 5). It has thread pools (called Executors) built right in. The Package's Summary page has some basic documentation. And many of the API pages for the various classes, such as the ThreadPoolExecutor class, also have some good documentation and examples.

With that API, you can create a series of Callables, wrap them in FutureTasks if needed, and put them into an Executor. The Callable interface is a lot like the Runnable interface, but it can return a result and throw exceptions that you get later when you go to get the results.

You might also want to look through the Concurrency section of the Java Tutorial. It discusses multi-threading and the concurrency API.

Lastly, I can recommend the books Java Concurrency in Practice {Addison-Wesley Professional, ISBN-10: 0-321-34960-1} and Java Threads 3rd Edition {O'Reilly, ISBN-13: 978-0-596-00782-9}. Both are good books. The latter was co-authored by JavaRanch's own Henry Wong. Henry moderates the Threads and Synchronization forum here at JavaRanch. So if you run into problems, post a question in that forum for some expert advice.

I hope that helps.
[ December 08, 2008: Message edited by: Mark Vedder ]
 
Iain Emsley
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark,

Many thanks, that helps a lot.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!