Solved

Slow for send out email

Posted on 2003-10-29
6
1,260 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
javap not working 8 60
jsp insert to database example 2 47
swing controls 2 16
wild fly 8 startup error 2 14
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
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:

820 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