Solved

Slow for send out email

Posted on 2003-10-29
6
1,251 Views
Last Modified: 2013-11-24
Dear all,

I've wrote a Java Program to send out email for around 15,000 mails, however I found that's really slow, it needs over 3 hours to send out by use Linux and sendmail on PIII 533 with 512MB RAM, can anyone help? Here is the looping of the program:

                        while (rs1.next()){
                                if(count%mailed == 0)
                                        {
                                                try{
                                                        Thread.sleep(sleepTime);
                                                }
                                                catch(InterruptedException e){
                                                        System.out.println("Sleep interrupted:"+e);
                                                }
                                        }
                                to = rs1.getString("vc_val");
                                jsendMail sendmail=new jsendMail(to, from,mailhost,subject);
                                sendmail.setMessage(fileContent1);
                                sendmail.startSend();
                                count++;
                                if(count%100 == 0){
                                        System.out.println(count + " mails sent");
                                }
                        }


while sleepTime is use for delay to slow the program to avoid sendmail open too much copies to receive data and jsendMail is a class to send out mail by using Java Mail.
0
Comment
Question by:monkeyjr
  • 2
6 Comments
 
LVL 14

Accepted Solution

by:
sudhakar_koundinya earned 125 total points
ID: 9647836
Ok I suggest you this procedure
     
     
      while (rs1.next()){

                               to = rs1.getString("vc_val");
                               vect.add(to); //add addresses to vector object first, do not execute mail sending program here
                       }

                   for(int i=0;i<vect.size();i+=1)// call mail sending program as new thread process
                   {
                                SendMailThread smt=new SendMailThread(vect.getAt(i));
                                        smt.start();
                                       if(i%50==0)  //sleep the mail process after it calss 50 send mail processes
                                      {
                                              try{
                                                       Thread.sleep(sleepTime);
                                               }
                                               catch(InterruptedException e){
                                                       System.out.println("Sleep interrupted:"+e);
                                               }
                                     }

                   }




And you need to write send mail thread class where you can send mail to the address that is fetched from the vector object

hope you got the idea

regards
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 9647871
if any problems are there in coding, sorry for that, but i suggest the idea of threading
and this is better process

public class SendMailThread extends Thread {

    private String to;
      String from, mailhost,subject, fileContent;

    public Producer(String to,String from, String mailhost, String subject, String fileContent) {
        this.to = to;
            // and other initailsations goes here liek this.from and blah blah blah
    }

    public void run() {
        jsendMail sendmail=new jsendMail(to, from,mailhost,subject);
                               sendmail.setMessage(fileContent1);
                               sendmail.startSend();
            try {
                sleep((int)(Math.random() * 100));
            } catch (InterruptedException e) { }
        }
    }
}



class YourProgram
{
      public static void main(String s[])
      {
            // your other codes
            while (rs1.next()){
                               if(count%mailed == 0)
                                       {
                                               try{
                                                       Thread.sleep(sleepTime);
                                               }
                                               catch(InterruptedException e){
                                                       System.out.println("Sleep interrupted:"+e);
                                               }
                                       }
                               to = rs1.getString("vc_val");
                               SendMailThread sendmailT=new SendMailThread(to, from,mailhost,subject,fileContent1);
                                             sendmailT.start();
                               count++;
                               if(count%100 == 0){
                                       System.out.println(count + " mails sent");
                               }
                       }
      }
}

0
 
LVL 35

Expert Comment

by:TimYates
ID: 9648511
Why are you sending out 15,000 emails?

Can I say now that my penis size is fine, I am not interested in seeing your 18th birthday, and if I am on your list, could you remove me :-(
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9648912
Tim:  ROLF ;-)
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Java asynchronous logging 4 50
eclipse compiler vs Installed JREs option 3 75
Responding to Java JComponent extended classes's resize event 4 50
Java DateChooser? 3 29
I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now