• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

Sending Emails

 
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. I have written a program to send the promotional emails with JavaMail

2. I have 18K+ emails and the program is going halt after sending 700/800 emails at a time.

3. What I did that I split these 18K+ emails into different categories and each category is not containing more than 500 emails. now I can send emails easily to my website members by selecting the category one by one

4. The problem is that I have to dedicate one operator to look after this process and select next category one by one that is time consuming job

5. I want to update my code in the way that it should send to one category then wait for 2/3 minutes and auto select next category and start sending again and continue this till the last category by itself

Thanks & kind regards
 
Rancher
Posts: 43015
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The java.util.Timer and TimerTask classes allow you to schedule threads for execution at specific times (or intervals). That way you can the next category for execution a few minutes after the previous one is done.
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Ulf Dittmer:
The java.util.Timer and TimerTask classes allow you to schedule threads for execution at specific times (or intervals). That way you can the next category for execution a few minutes after the previous one is done.



great!
I learned a lot from this forum

Thanks a lot
 
Ranch Hand
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assuming that one can't predict the time taken to send an email batch and since I would expect this process to be running in just one thread then I would have thought a simple sleep() would have been easier than setting up a timer.
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for both favorable replies but am little bit confused. Please let me know that how will I know that the category is finished and new category came then wait 2/minutes or sleep() and after 2 minutes start the next category with java timer or sleep()

//I am getting emails from oracle db with the conditions that:

[ October 12, 2008: Message edited by: Farakh khan ]
 
Ulf Dittmer
Rancher
Posts: 43015
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe I'm not understanding what you're asking, but the category is finished when the "while (rs.next())" is through, no? Then you can put the Thread to sleep for a few minutes as James suggested, or start a new thread for the next category, as I suggested.
[ October 12, 2008: Message edited by: Ulf Dittmer ]
 
James Sabre
Ranch Hand
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Farakh khan:
Thanks for both favorable replies but am little bit confused.



I'm now a little confused. You seem to be trying to run this code from within a Servlet since you are writing HTML to 'out'. I was expecting you to be using a simple Java main program when the code would be almost trivial. In essence


If you try to do this in a Servlet then you could end up with the Servlet response timing out. Even if you invoke a Java Timer from withing the Servlet you could still have this timeout problem.

Is it absolutely necessary to use a Servlet to invoke this?
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Ulf Dittmer:
[QB]Maybe I'm not understanding what you're asking, but the category is finished when the "while (rs.next())" is through, no?



if i remove the category then its mean the whole categories. You are right.

Then you can put the Thread to sleep for a few minutes as James suggested,



Will I achieve my target with the removal of setting category and writing the following changes in the code:


or start a new thread for the next category, as I suggested.


Here I am confused that how the program will know that the category that current category finished or what is next category

Thanks again & best regards
 
Ulf Dittmer
Rancher
Posts: 43015
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You said you already have the code to get the records in "categories" -whatever those are- and that it works fine that way. So the code should contain the logic to get records by category; can't it call "Thread.sleep(300000)" or something similar after it sent the emails for each category, before it moves on to the next one?
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by James Sabre:


I'm now a little confused. You seem to be trying to run this code from within a Servlet since you are writing HTML to 'out'. I was expecting you to be using a simple Java main program when the code would be almost trivial. In essence


If you try to do this in a Servlet then you could end up with the Servlet response timing out. Even if you invoke a Java Timer from withing the Servlet you could still have this timeout problem.

Is it absolutely necessary to use a Servlet to invoke this?



Great!
Actually I posted my previous thread without seeing your this reply.

Please correct me if I am wrong:
 
James Sabre
Ranch Hand
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Farakh khan:


Great!
Actually I posted my previous thread without seeing your this reply.

Please correct me if I am wrong:

{/QUOTE]

Since each JDBC connection can only have one active ResultSet you will need two connections or you will need to build a collection of categories from the first query and to iterate over that collection using the value in the second query.

 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Since each JDBC connection can only have one active ResultSet you will need two connections or you will need to build a collection of categories from the first query and to iterate over that collection using the value in the second query.[/QB]



1) Can you please help me to correct my this code? That will be your kind enough. ohh you mean rs1.next() and rs1.getString(1) will solve the problem

2) Have I inserted the sleep() on accurate place?

Thanks again

[ October 12, 2008: Message edited by: Farakh khan ]
[ October 12, 2008: Message edited by: Farakh khan ]
 
James Sabre
Ranch Hand
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Farakh khan:


1) Can you please help me to correct my this code? That will be your kind enough. ohh you mean rs1.next() will solve the problem

2) Have I inserted the sleep() on accurate place?

Thanks again

[ October 12, 2008: Message edited by: Farakh khan ]



Since you have created one JDBC connection I assume you should have no trouble creating a second JDBC connection. Am I missing something?

And yes, you have put the sleep in about the right place.
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by James Sabre:


Since you have created one JDBC connection I assume you should have no trouble creating a second JDBC connection. Am I missing something?

And yes, you have put the sleep in about the right place.



I think I can use the same JDBC connection for getting two different result sets. right or wrong? please correct me

thanks agin
 
James Sabre
Ranch Hand
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Farakh khan:


I think I can use the same JDBC connection for getting two different result sets. right or wrong? please correct me

thanks agin



I already have corrected you. You can't have two active ResultSet for a single javax.sql.Connection and since you are creating a second ResultSet for your connection inside a loop iterating over your first the first will fail the second time round. You need two Connections to do it the way of your current logic.
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by James Sabre:


I already have corrected you. You can't have two active ResultSet for a single javax.sql.Connection and since you are creating a second ResultSet for your connection inside a loop iterating over your first the first will fail the second time round. You need two Connections to do it the way of your current logic.





is that ok 100%?

Regards
 
James Sabre
Ranch Hand
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The logic looks to be correct but there is at least one syntax error which I will leave you to correct.

Since you have not shown the generation of the Connection objects I have to assume you have done this correctly. I do hope you have not just created a second reference to the original connection!
 
I suggest huckleberry pie. But the only thing on the gluten free menu is this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic