Hi, I have a table that has these columns : email address subject body status ( S for sent, N for not sent)
I am new to threads, I want to create a program that : 1) Query the table 2) Test the the flag status, if status is equal to N, send an email and update the status from N to S. Note : the emails are differentes. The table is very big (lot of rows), step (2) when sending email slow the process, Any idea on how to implement this Your help is apprecited. Thanks
It's important that the constructor (or some set methods) pass all the required data and the sendMail() has no arguments. Get that thoroughly debugged and working.
Then look into the Apache Commons Thread Pool. That lets you put a bunch of "runnable" objects into a queue where some number of threads can get them and run them. (JDK 1.5/5.0 has similar facilities.)
Next add "implements runnable" to your worker class, and code the run() method to call sendMail(). Create one object per mail destination, put all those objects into the queue and let er rip.
Lemme know if that made sense and if it works out for you.
Editing: Ooops, I forgot the usual warning. If your program is CPU bound then multiple threads won't speed it up and may even slow it down. But if every time it hits the send API on JavaMail or whatever you're using it has to wait several seconds for the mail server to respond then threads might be way cool.
[ July 10, 2004: Message edited by: Stan James ] [ July 10, 2004: Message edited by: Stan James ]
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Joined: Jun 26, 2001
Hi, could someone please help me on how to build this class, Mr Stan James show me how to do it, I am new to this , please I need your help. thanks
Joined: Jan 29, 2003
Start by breaking the problem into the smallest possible bits. Do you know enough of the JavaMail API to send a message? (I don't!) If so, make this run: