Spring emails: when using @Async exceptions are caught by SimpleAsyncUncaughtExceptio...
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Sat, 26 Mar 2016 00:08:51 +0000 (01:08 +0100)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Sat, 26 Mar 2016 00:08:51 +0000 (01:08 +0100)
SpringJava/Emails/spring-emails-web-client/src/main/java/de/spring/webservices/rest/controller/EmailController.java
SpringJava/Emails/spring-emails-web-client/src/main/resources/spring-configuration/spring-configuration.xml

index 583e66a..56e98f4 100644 (file)
@@ -54,6 +54,9 @@ public class EmailController {
                try {
                        emailService.sendEmailAsync(to, emailSubject, emailText, true, null, inline);
                } catch (MessagingException ex) {
+                       // WARNING!!!!
+                       // Because we are using @Async we will never catch thrown exceptions from sendEmailAsync.
+                       // Exceptions will be caught by org.springframework.aop.interceptor.SimpleAsyncUncaughtExceptionHandler. :(
                        LOGGER.error("Send email error", ex);
                }
     }
index 4589e60..e12ef32 100644 (file)
@@ -24,7 +24,7 @@
     <!--  Enable Asynchronous Spring Tasks -->
        <task:annotation-driven />
        <task:executor id="asyncEmailSender" pool-size="1-10" keep-alive="60"
-               queue-capacity="10" rejection-policy="CALLER_RUNS" />
+               queue-capacity="0" rejection-policy="CALLER_RUNS" />
        
 
        <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">