Only 48 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

send email 24H from a table ??  RSS feed

 
majid nakit
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make a class that can do all the work, like

new MailSender(required parameters).sendMail();

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 ]
 
majid nakit
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:


Then see what part seems easy to carve off next.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!