i have a spring boot aplication and i want send email with javamail using ses on aws. but if I send an email, while it and sent no other process is executed. I want to send the email through a thread, but I've implemented a thread in this way and even then the email sending process is not asynchronous. when I make this request to send email and then list all to see how the processing is, as long as the sending of the email does not finish the list request is not executed
@GetMapping
public ResponseEntity<?> listarUsuarios(){
System.out.println("--------begin send mail------------");
new SendMail(emailService).run();
System.out.println("--------finish send mail------------");
List<Usuario> usuariosList = usuarioRepository.findAll(); // <- this process not is processed when send email not finish
return new ResponseEntity<>(usuariosList,HttpStatus.OK);
}
.
public class SendMail extends Thread {
public EmailService emailService;
public SendMail(EmailService emailService) {
this.emailService = emailService;
}
public void run(){
try {
emailService.EnviarEmailDeConfirmacao("daviresio@gmail.com", 1, "Subject test mail","body test mail");
} catch (Exception e) {
e.printStackTrace();
}
}
}