• Involved source code address github.com/Wasabi1234/…

Introduction – Personalized electronic billing

● Success rate of mail delivery There is a certain requirement for the success rate of mail delivery. Because a large number of mails will be mistaken as spam by the recipient’s mail server, Therefore, some fake data should be added to the header of the message to avoid being mistaken for spam by the anti-spam engine

Considering from two aspects of the advertising letter sending and electronic billing system’s function and how to consider the advertising letter – this module is developed Since it is spam mail, certainly need a template, then the information to our clients from the database one by one, into the template to generate a complete email, and then throw to send to the transmitter


Send the electronic billing class diagram

  • Advertisement letter template


  • Mail class code


  • Business Scenario Class



Think carefully, is there something wrong with this program? This is a thread running, which is what you send is single-threaded, that according to an email sent out about 0.02 seconds (small enough, do you want to go to fetch the data in the database), 6 million mails to 33 hours, as well as a send don’t finish all day, didn’t send out today, tomorrow’s bills and produced, accumulate over a long period, What if it provokes a lot of complaints from party A’s staff?

Ok, change sendMail to multithreaded, but there’s still a problem with just changing sendMail to multithreaded. Create the first mail object, run it in thread 1, and before it’s sent out, thread 2 starts, and just change the recipient address and name of the mail object, so the thread is not safe. You could say that there are N ways to solve this problem, one of which is to use a new pattern to solve this problem: by copying objects, the class diagram is slightly modified


Revised class diagram for sending electronic bills

  • The clone() method is overridden by the clone() method in the Mail class


1 Definition and type


2 Application Scenarios

Three advantages

4 faults

5 extension