Question: 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.

Answer: 
You can make the mail sending method `@Async`. This way Spring will execute this in a seperate thread. Read this blog post about it: [Creating Asynchronous Methods](https://spring.io/guides/gs/async-method/)
Consider creating a separate thread to send emails within your application. This will allow parallel execution(application+email sending).

If you would want another approach you can create a separate back end application that only sends emails. Although you will need to submit the email messages to the application. An asynchronous way to do this is to send a JMS message to the email application.