定期发送大宗邮件

时间:2017-05-19 11:48:34

标签: java spring-boot architecture restful-architecture

我有一个要求,我必须发送100邮件/分钟/用户,并且它是特定时间的。(即所有邮件,即100 * 1000 = 10000邮件/分钟应该同时进行)

目前有近1000名用户。

对于每封电子邮件,我先保存,然后发送。

为了获得更好的绩效并以最佳方式实现目标,我需要实施哪些事项。

[注意:所有电子邮件都是通过不同的帐户发送的,所以限制不会增加]

任何建议都会非常有用。

我目前正在为项目使用Spring Boot。

2 个答案:

答案 0 :(得分:1)

//Remember to set @EnableScheduling
//in the class containing your main method
@SpringBootApplication
@EnableScheduling
@EnableAsync
public class Application {

    public static void main(String[] args) throws Exception {
        SpringApplication.run(Application.class);
    }
}

@Component
public class ScheduledTasks {

    List<Email> listOfEmails;

    int nextBatch = 50;
    int curBatch = 0;

    //This method will run every 15 second.
    @Scheduled(fixedDelay = 15000)
    public void yourMethodName() {
        //This will process all of your objects all at once using treads
        for(int i = curBatch; i < maxBatchSize(); i++){
            listOfEmails.get(i).process();
        }
        nextBatch+=50;
        curBatch+=50;
    }

    private int maxBatchSize(){
        if(nextBatch < listOfEmails.size()){
            return nextBatch;
        } else {
            return listOfEmails.size();
        }
    }
}



public class YourObject {

    Integer someTest = 0;

    @Async
    public void process(Email e) {
        e.send();
    }
}

答案 1 :(得分:0)

如果项目在Windows服务器上运行,则可以使用Windows服务。

相关问题