在我的 spring-boot 项目中,我有一个功能,发送电子邮件,在电子邮件中,在事务内发送需要太多时间。
//service layer
@Transaction
function inviteUser() {
// insert in invitation table
// insert in invitation sub-table
// sending mail to user (30 seconds)
}
发送邮件大约需要 30 秒,我该如何克服这个问题。有没有其他特定的方法来实现这种功能。
最佳答案
在spring-boot中你可以使用@Async注解,
@Transactional
public void register() {
//after success call that method
emailService.sendWelcomeMail();
}
@Service
@Configuration
@EnableAsync
public class EmailService {
// for sending email
@Async
public void sendWelcomeMail(){}
}
关于java - 在java中发送邮件需要太多时间,我该如何克服这个问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43758473/