[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Slow for send out email

Posted on 2003-10-29
6
Medium Priority
?
1,271 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
6 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

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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 …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

649 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