jeudi 26 mars 2015

How can I separate business logic and email sending functionality?



I have a requirement in my java web application where I need to send email alerts for certain conditions. For this I have used javax mail api and sending email works just fine. But the problem is the programs executions waits until the methods for sending the email are executed. As there are hundreds of email to be sent at various points ... this reduces the performance significantly.


I am using spring and have also used spring aop. Can anyone suggest me how can I separate my business logic and sending email functionality. It should be like -


Sending emails is my advice which gets executed when xyz method is called - So main execution should not wait for advice to finish its execution rather it should return back and execute further business logic thus email sending executed separately.


Here creating new threads seems obvious choice. But I think there could be some better way, is there? Thanks.




Aucun commentaire:

Enregistrer un commentaire