gpt4 book ai didi

java - Jhipster:异步 sendemail() 一段时间后停止工作

转载 作者:行者123 更新时间:2023-12-02 11:57:24 25 4
gpt4 key购买 nike

在我的 Jhipster 应用程序中,异步 sendemail() 方法在部署一段时间后停止工作。我认为问题出在异步配置中。有人可以帮助我吗。

下面是我的异步配置代码

  public Executor getAsyncExecutor() {
log.debug("Creating Async Task Executor");
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(jHipsterProperties.getAsync().getCorePoolSize());
executor.setMaxPoolSize(jHipsterProperties.getAsync().getMaxPoolSize());
executor.setQueueCapacity(jHipsterProperties.getAsync().getQueueCapacity());
executor.setThreadNamePrefix("investhry-Executor-");
return new ExceptionHandlingAsyncTaskExecutor(executor);
}

发送电子邮件的方法描述如下:

@Async
public void sendEmail(String to, String subject, String content, boolean isMultipart, boolean isHtml) {
log.debug("Send e-mail[multipart '{}' and html '{}'] to '{}' with subject '{}' and content={}",
isMultipart, isHtml, to, subject, content);

// Prepare message using a Spring helper
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
try {
MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, CharEncoding.UTF_8);
message.setTo(to);
message.setFrom(jHipsterProperties.getMail().getFrom());
message.setSubject(subject);
message.setText(content, isHtml);
javaMailSender.send(mimeMessage);
log.debug("Sent e-mail to User '{}'", to);
} catch (Exception e) {
log.warn("E-mail could not be sent to user '{}'", to, e);
}
}

最佳答案

我已经找到问题所在了。问题不在于您的异步执行器,而在于 JAVA Mail API .

transport.send()(最终用于发送电子邮件)的超时值是无限的。因此所有异步线程都处于等待状态。如果你将其更改为某个值,例如

       mailprop.put("mail.smtp.timeout", 1000);

您可以查看此解决方案 here

关于java - Jhipster:异步 sendemail() 一段时间后停止工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47505789/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com