Solved

Slow for send out email

Posted on 2003-10-29
6
1,248 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Tim:  ROLF ;-)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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…
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…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

763 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

13 Experts available now in Live!

Get 1:1 Help Now