[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Slow for send out email

Posted on 2003-10-29
6
Medium Priority
?
1,272 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
4 Comments
 
LVL 14

Accepted Solution

by:
sudhakar_koundinya earned 500 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

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses
Course of the Month18 days, 12 hours left to enroll

834 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