0

In my Jhipster application the Async sendemail() method stops working after sometime of deployment.I think the problem is in the async configuration.Can somebody help me with it.

Below is my code for Async Configuration

  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);
}

And Send email method is described below:

@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);
    }
}
Harshit Bhatt
  • 133
  • 2
  • 12

1 Answers1

1

I have figured out the problem. The problem is not with your Async Executer but with the JAVA Mail API.

The timeout value for transport.send() (which eventually is used to send the email) is infinite.So all you asynchronous threads are in waiting state. If you change it to some value like

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

You can check out this solution here