Spring @ Asyn c не возвращается сразу - PullRequest
1 голос
/ 07 апреля 2020

У меня есть приложение Spring Boot среднего размера, использующее: Spring Data REST, Spring HATEOAS, Spring JPA, Hibernate.

У меня есть некоторые проблемы с использованием @ Asyn c: метод, аннотированный таким образом не возвращается немедленно к вызывающей стороне, даже если он создал новый поток для выполнения ( Spring do c).

Это моя конфигурация:

@Configuration
@EnableAsync
public class AsyncConfiguration implements AsyncConfigurer {

    @Override
    public Executor getAsyncExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(2);
        executor.setMaxPoolSize(10);
        executor.setQueueCapacity(500);
        executor.setThreadNamePrefix("myThreadAsync");
        executor.initialize();
        return executor;
    }
}

это компонент с методом @ Asyn c:

@Component
@Log4j2
public class OrderCommunicationBuilder {


    @Async
    public void sendEmailPendingOrder(Tenant tenant, String orderSid, String paymentDetails) {

       // Some stuff
    }
}

, и этот сервис вызывает этот метод:

@Service
@Transactional(value = "managementTransactionManager")
@Log4j2
public class TenantService {

     public Optional<Order> upgradePlanForCurrentTenant(Plan plan, int users, int stores, PaymentType paymentType) {
      //some stuff saving data via HIbernate in DB

      orderCommunicationBuilder.sendEmailPendingOrder(order.getTenant(), order.getSid(),order.getPaymentDetails());//this is async

      //some other stuff
      return Optional.ofNullable(order);
    }
}

Это контроллер REST, который использует service:

@Profile({"dev", "stage", "prod"})
@RepositoryRestController
@RequestMapping(path = "/api/v1")
@Log4j2
public class TenantController {

    @PreAuthorize("isAuthenticated()")
    @PostMapping(path = "/tenants/current/subscription/renewal")
    public ResponseEntity<?> renewal(@RequestBody Map<String, Object> data, PersistentEntityResourceAssembler resourceAssembler) {
        //Some stuff
        Optional<Order> optionalOrder = tenantService.upgradePlanForCurrentTenant(plan, users, stores, paymentType); //this call remains pending until OrderCommunicationBuilder#sendEmailPendingOrder doesn't finish
        if (optionalOrder.isPresent()) {
            return ResponseEntity.ok(resourceAssembler.toModel(optionalOrder.get()));
        }
        throw new InternalException(ExceptionCode.INTERNAL_ERROR);
    }

}

Я включил журнал Spring и вижу, что при вызове метода sendEmailPendingOrder() создается новый поток, однако TenantController остается в ожидании до тех пор, пока OrderCommunicationBuilder#sendEmailPendingOrder не закончится, но не должно!

Некоторые соответствующие журналы:

 07/04/2020 15:23:11,989 DEBUG http-nio-8082-exec-9 FilterChainProxy:328 - /api/v1/tenants/current/subscription/renewal at position 1 of 14 in additional filter chain; firing Filter: 'WebAsyncManagerIntegrationFilter'
07/04/2020 15:23:11,989 DEBUG http-nio-8082-exec-9 FilterChainProxy:328 - /api/v1/tenants/current/subscription/renewal at position 2 of 14 in additional filter chain; firing Filter: 'SecurityContextPersistenceFilter'
07/04/2020 15:23:11,989 DEBUG http-nio-8082-exec-9 HttpSessionSecurityContextRepository:173 - No HttpSession currently exists
07/04/2020 15:23:11,989 DEBUG http-nio-8082-exec-9 HttpSessionSecurityContextRepository:117 - No SecurityContext was available from the HttpSession: null. A new one will be created.
07/04/2020 15:23:11,989 DEBUG http-nio-8082-exec-9 FilterChainProxy:328 - /api/v1/tenants/current/subscription/renewal at position 3 of 14 in additional filter chain; firing Filter: 'HeaderWriterFilter'
07/04/2020 15:23:11,990 DEBUG http-nio-8082-exec-9 FilterChainProxy:328 - /api/v1/tenants/current/subscription/renewal at position 4 of 14 in additional filter chain; firing Filter: 'LogoutFilter'
07/04/2020 15:23:11,990 DEBUG http-nio-8082-exec-9 OrRequestMatcher:65 - Trying to match using Ant [pattern='/logout', GET]
07/04/2020 15:23:11,990 DEBUG http-nio-8082-exec-9 AntPathRequestMatcher:157 - Request 'POST /api/v1/tenants/current/subscription/renewal' doesn't match 'GET /logout'
07/04/2020 15:23:11,990 DEBUG http-nio-8082-exec-9 OrRequestMatcher:65 - Trying to match using Ant [pattern='/logout', POST]
07/04/2020 15:23:11,990 DEBUG http-nio-8082-exec-9 AntPathRequestMatcher:177 - Checking match of request : '/api/v1/tenants/current/subscription/renewal'; against '/logout'
07/04/2020 15:23:11,990 DEBUG http-nio-8082-exec-9 OrRequestMatcher:65 - Trying to match using Ant [pattern='/logout', PUT]
07/04/2020 15:23:11,990 DEBUG http-nio-8082-exec-9 AntPathRequestMatcher:157 - Request 'POST /api/v1/tenants/current/subscription/renewal' doesn't match 'PUT /logout'
07/04/2020 15:23:11,990 DEBUG http-nio-8082-exec-9 OrRequestMatcher:65 - Trying to match using Ant [pattern='/logout', DELETE]
07/04/2020 15:23:11,990 DEBUG http-nio-8082-exec-9 AntPathRequestMatcher:157 - Request 'POST /api/v1/tenants/current/subscription/renewal' doesn't match 'DELETE /logout'
07/04/2020 15:23:11,990 DEBUG http-nio-8082-exec-9 OrRequestMatcher:72 - No matches found
07/04/2020 15:23:11,990 DEBUG http-nio-8082-exec-9 FilterChainProxy:328 - /api/v1/tenants/current/subscription/renewal at position 5 of 14 in additional filter chain; firing Filter: 'TenantFilter'
07/04/2020 15:23:11,990 DEBUG http-nio-8082-exec-9 FilterChainProxy:328 - /api/v1/tenants/current/subscription/renewal at position 6 of 14 in additional filter chain; firing Filter: 'JwtAuthenticationTokenFilter'
07/04/2020 15:23:12,138 DEBUG http-nio-8082-exec-9 FilterChainProxy:328 - /api/v1/tenants/current/subscription/renewal at position 7 of 14 in additional filter chain; firing Filter: 'CookieAuthFilter'
07/04/2020 15:23:12,138 DEBUG http-nio-8082-exec-9 FilterChainProxy:328 - /api/v1/tenants/current/subscription/renewal at position 8 of 14 in additional filter chain; firing Filter: 'UsernamePasswordAuthenticationFilter'
07/04/2020 15:23:12,138 DEBUG http-nio-8082-exec-9 AntPathRequestMatcher:177 - Checking match of request : '/api/v1/tenants/current/subscription/renewal'; against '/login'
07/04/2020 15:23:12,138 DEBUG http-nio-8082-exec-9 FilterChainProxy:328 - /api/v1/tenants/current/subscription/renewal at position 9 of 14 in additional filter chain; firing Filter: 'RequestCacheAwareFilter'
07/04/2020 15:23:12,138 DEBUG http-nio-8082-exec-9 HttpSessionRequestCache:95 - saved request doesn't match
07/04/2020 15:23:12,138 DEBUG http-nio-8082-exec-9 FilterChainProxy:328 - /api/v1/tenants/current/subscription/renewal at position 10 of 14 in additional filter chain; firing Filter: 'SecurityContextHolderAwareRequestFilter'
07/04/2020 15:23:12,138 DEBUG http-nio-8082-exec-9 FilterChainProxy:328 - /api/v1/tenants/current/subscription/renewal at position 11 of 14 in additional filter chain; firing Filter: 'AnonymousAuthenticationFilter'

07/04/2020 15:23:12,138 DEBUG http-nio-8082-exec-9 FilterChainProxy:328 - /api/v1/tenants/current/subscription/renewal at position 12 of 14 in additional filter chain; firing Filter: 'SessionManagementFilter'
07/04/2020 15:23:12,139 DEBUG http-nio-8082-exec-9 CompositeSessionAuthenticationStrategy:87 - Delegating to org.springframework.security.web.authentication.session.ChangeSessionIdAuthenticationStrategy@7ce03100
07/04/2020 15:23:12,139 DEBUG http-nio-8082-exec-9 HttpSessionSecurityContextRepository:426 - HttpSession being created as SecurityContext is non-default

07/04/2020 15:23:12,139 DEBUG http-nio-8082-exec-9 FilterChainProxy:328 - /api/v1/tenants/current/subscription/renewal at position 13 of 14 in additional filter chain; firing Filter: 'ExceptionTranslationFilter'
07/04/2020 15:23:12,139 DEBUG http-nio-8082-exec-9 FilterChainProxy:328 - /api/v1/tenants/current/subscription/renewal at position 14 of 14 in additional filter chain; firing Filter: 'FilterSecurityInterceptor'
07/04/2020 15:23:12,139 DEBUG http-nio-8082-exec-9 AntPathRequestMatcher:157 - Request 'POST /api/v1/tenants/current/subscription/renewal' doesn't match 'OPTIONS /**'
07/04/2020 15:23:12,139 DEBUG http-nio-8082-exec-9 AntPathRequestMatcher:177 - Checking match of request : '/api/v1/tenants/current/subscription/renewal'; against '/alexa'
07/04/2020 15:23:12,139 DEBUG http-nio-8082-exec-9 AntPathRequestMatcher:177 - Checking match of request : '/api/v1/tenants/current/subscription/renewal'; against '/socket/**'
07/04/2020 15:23:12,139 DEBUG http-nio-8082-exec-9 AntPathRequestMatcher:177 - Checking match of request : '/api/v1/tenants/current/subscription/renewal'; against '/images/**'
07/04/2020 15:23:12,139 DEBUG http-nio-8082-exec-9 AntPathRequestMatcher:177 - Checking match of request : '/api/v1/tenants/current/subscription/renewal'; against '/resources/templates/**'
07/04/2020 15:23:12,140 DEBUG http-nio-8082-exec-9 AntPathRequestMatcher:177 - Checking match of request : '/api/v1/tenants/current/subscription/renewal'; against '/api/v1/notifications/**'
07/04/2020 15:23:12,140 DEBUG http-nio-8082-exec-9 AntPathRequestMatcher:177 - Checking match of request : '/api/v1/tenants/current/subscription/renewal'; against '/actuator/**'
07/04/2020 15:23:12,140 DEBUG http-nio-8082-exec-9 AntPathRequestMatcher:177 - Checking match of request : '/api/v1/tenants/current/subscription/renewal'; against '/v2/api-docs'
07/04/2020 15:23:12,140 DEBUG http-nio-8082-exec-9 AntPathRequestMatcher:177 - Checking match of request : '/api/v1/tenants/current/subscription/renewal'; against '/swagger-accounts/configuration/ui'
07/04/2020 15:23:12,140 DEBUG http-nio-8082-exec-9 AntPathRequestMatcher:177 - Checking match of request : '/api/v1/tenants/current/subscription/renewal'; against '/swagger-accounts'
07/04/2020 15:23:12,140 DEBUG http-nio-8082-exec-9 AntPathRequestMatcher:177 - Checking match of request : '/api/v1/tenants/current/subscription/renewal'; against '/swagger-accounts/configuration/security'
07/04/2020 15:23:12,140 DEBUG http-nio-8082-exec-9 AntPathRequestMatcher:177 - Checking match of request : '/api/v1/tenants/current/subscription/renewal'; against '/swagger-ui.html'
07/04/2020 15:23:12,140 DEBUG http-nio-8082-exec-9 AntPathRequestMatcher:177 - Checking match of request : '/api/v1/tenants/current/subscription/renewal'; against '/webjars/**'
07/04/2020 15:23:12,140 DEBUG http-nio-8082-exec-9 AntPathRequestMatcher:177 - Checking match of request : '/api/v1/tenants/current/subscription/renewal'; against '/swagger-resources/**'
07/04/2020 15:23:12,141 DEBUG http-nio-8082-exec-9 AntPathRequestMatcher:177 - Checking match of request : '/api/v1/tenants/current/subscription/renewal'; against '/api/v1/public/**'
07/04/2020 15:23:12,141 DEBUG http-nio-8082-exec-9 AntPathRequestMatcher:177 - Checking match of request : '/api/v1/tenants/current/subscription/renewal'; against '/api/v1/auth/**'
07/04/2020 15:23:12,141 DEBUG http-nio-8082-exec-9 AntPathRequestMatcher:177 - Checking match of request : '/api/v1/tenants/current/subscription/renewal'; against '/api/v1/formLogin/**'
07/04/2020 15:23:12,141 DEBUG http-nio-8082-exec-9 AntPathRequestMatcher:177 - Checking match of request : '/api/v1/tenants/current/subscription/renewal'; against '/api/v1/logout'
07/04/2020 15:23:12,141 DEBUG http-nio-8082-exec-9 AntPathRequestMatcher:177 - Checking match of request : '/api/v1/tenants/current/subscription/renewal'; against '/api/v1/agents/verifyEmail'
07/04/2020 15:23:12,141 DEBUG http-nio-8082-exec-9 AntPathRequestMatcher:177 - Checking match of request : '/api/v1/tenants/current/subscription/renewal'; against '/api/v1/agents/**/verificationToken'
07/04/2020 15:23:12,141 DEBUG http-nio-8082-exec-9 AntPathRequestMatcher:177 - Checking match of request : '/api/v1/tenants/current/subscription/renewal'; against '/api/v1/agents/**/resetPassword'
07/04/2020 15:23:12,141 DEBUG http-nio-8082-exec-9 AntPathRequestMatcher:177 - Checking match of request : '/api/v1/tenants/current/subscription/renewal'; against '/api/v1/agents/**/verifyPasswordReset'
07/04/2020 15:23:12,142 DEBUG http-nio-8082-exec-9 AntPathRequestMatcher:177 - Checking match of request : '/api/v1/tenants/current/subscription/renewal'; against '/api/v1/agents/**/changePassword'
07/04/2020 15:23:12,142 DEBUG http-nio-8082-exec-9 AntPathRequestMatcher:177 - Checking match of request : '/api/v1/tenants/current/subscription/renewal'; against '/api/v1/errors/**'
07/04/2020 15:23:12,142 DEBUG http-nio-8082-exec-9 AntPathRequestMatcher:177 - Checking match of request : '/api/v1/tenants/current/subscription/renewal'; against '/api/v1/verifyCaptcha'
07/04/2020 15:23:12,142 DEBUG http-nio-8082-exec-9 AntPathRequestMatcher:177 - Checking match of request : '/api/v1/tenants/current/subscription/renewal'; against '/api/v1/ping'
07/04/2020 15:23:12,142 DEBUG http-nio-8082-exec-9 AntPathRequestMatcher:177 - Checking match of request : '/api/v1/tenants/current/subscription/renewal'; against '/api/v1/tenants'
07/04/2020 15:23:12,142 DEBUG http-nio-8082-exec-9 AntPathRequestMatcher:157 - Request 'POST /api/v1/tenants/current/subscription/renewal' doesn't match 'GET /api/v1/tenants/**/availability'
07/04/2020 15:23:12,142 DEBUG http-nio-8082-exec-9 AntPathRequestMatcher:177 - Checking match of request : '/api/v1/tenants/current/subscription/renewal'; against '/api/v1/alcon/**/image'
07/04/2020 15:23:12,142 DEBUG http-nio-8082-exec-9 AntPathRequestMatcher:177 - Checking match of request : '/api/v1/tenants/current/subscription/renewal'; against '/api/v1/avm/**/image'
07/04/2020 15:23:12,142 DEBUG http-nio-8082-exec-9 AntPathRequestMatcher:177 - Checking match of request : '/api/v1/tenants/current/subscription/renewal'; against '/api/v1/marcolin/**/image'
07/04/2020 15:23:12,142 DEBUG http-nio-8082-exec-9 AntPathRequestMatcher:177 - Checking match of request : '/api/v1/tenants/current/subscription/renewal'; against '/api/v1/trevi/**/image'
07/04/2020 15:23:12,143 DEBUG http-nio-8082-exec-9 AntPathRequestMatcher:177 - Checking match of request : '/api/v1/tenants/current/subscription/renewal'; against '/api/v1/area98/**/image'
07/04/2020 15:23:12,143 DEBUG http-nio-8082-exec-9 AntPathRequestMatcher:177 - Checking match of request : '/api/v1/tenants/current/subscription/renewal'; against '/api/v1/diesse/**/image'
07/04/2020 15:23:12,143 DEBUG http-nio-8082-exec-9 AntPathRequestMatcher:157 - Request 'POST /api/v1/tenants/current/subscription/renewal' doesn't match 'GET /api/v1'
07/04/2020 15:23:12,143 DEBUG http-nio-8082-exec-9 AntPathRequestMatcher:167 - Request '/api/v1/tenants/current/subscription/renewal' matched by universal pattern '/**'
07/04/2020 15:23:12,143 DEBUG http-nio-8082-exec-9 FilterSecurityInterceptor:219 - Secure object: FilterInvocation: URL: /api/v1/tenants/current/subscription/renewal; Attributes: [authenticated]

07/04/2020 15:23:12,143 DEBUG http-nio-8082-exec-9 AffirmativeBased:66 - Voter: org.springframework.security.web.access.expression.WebExpressionVoter@39ef6da6, returned: 1
07/04/2020 15:23:12,143 DEBUG http-nio-8082-exec-9 FilterSecurityInterceptor:243 - Authorization successful
07/04/2020 15:23:12,143 DEBUG http-nio-8082-exec-9 FilterSecurityInterceptor:256 - RunAsManager did not change Authentication object
07/04/2020 15:23:12,144 DEBUG http-nio-8082-exec-9 FilterChainProxy:313 - /api/v1/tenants/current/subscription/renewal reached end of additional filter chain; proceeding with original chain
07/04/2020 15:23:12,144 DEBUG http-nio-8082-exec-9 DispatcherServlet:91 - POST "/api/v1/tenants/current/subscription/renewal", parameters={}
07/04/2020 15:23:12,144 DEBUG http-nio-8082-exec-9 RequestMappingHandlerMapping:414 - Mapped to com.test.server.rest.controllers.tenants.TenantController#renewal(Map, PersistentEntityResourceAssembler)
07/04/2020 15:23:12,145 DEBUG http-nio-8082-exec-9 RequestResponseBodyMethodProcessor:91 - Read "application/json;charset=UTF-8" to [{plan=http://xx.xx.xx.xx:8082/api/v1/plans/4, users=5, stores=2, paymentType=BANK_TRANSFER}]
07/04/2020 15:23:12,145 DEBUG http-nio-8082-exec-9 MethodSecurityInterceptor:219 - Secure object: ReflectiveMethodInvocation: public org.springframework.http.ResponseEntity com.test.server.rest.controllers.tenants.TenantController.renewal(java.util.Map,org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler); target is of class [com.test.server.rest.controllers.tenants.TenantController]; Attributes: [[authorize: 'isAuthenticated()', filter: 'null', filterTarget: 'null']]
07/04/2020 15:23:12,146 DEBUG http-nio-8082-exec-9 AffirmativeBased:66 - Voter: org.springframework.security.access.prepost.PreInvocationAuthorizationAdviceVoter@a3c2c4e, returned: 1
07/04/2020 15:23:12,146 DEBUG http-nio-8082-exec-9 MethodSecurityInterceptor:243 - Authorization successful
07/04/2020 15:23:12,146 DEBUG http-nio-8082-exec-9 MethodSecurityInterceptor:256 - RunAsManager did not change Authentication object
07/04/2020 15:23:12,203 DEBUG http-nio-8082-exec-9 DataSourceUtils:186 - Setting JDBC Connection [HikariProxyConnection@1902501765 wrapping com.mysql.cj.jdbc.ConnectionImpl@511ad0dd] read-only
07/04/2020 15:23:12,374 DEBUG http-nio-8082-exec-9 DataSourceUtils:250 - Resetting read-only flag of JDBC Connection [HikariProxyConnection@1902501765 wrapping com.mysql.cj.jdbc.ConnectionImpl@511ad0dd]
07/04/2020 15:23:12,436  WARN http-nio-8082-exec-9 EntityManagerEnabledFilterAspect:34 - Unable to enable filter
07/04/2020 15:23:12,437  WARN http-nio-8082-exec-9 EntityManagerStoreFilterAspect:41 - Unable to enable filter
07/04/2020 15:23:12,437  WARN http-nio-8082-exec-9 EntityManagerStoreFilterAspect:41 - Unable to enable filter
07/04/2020 15:23:12,494  INFO http-nio-8082-exec-9 TenantService:387 - Tenant pianetatecno (31) is renewing plan
07/04/2020 15:23:12,495 DEBUG http-nio-8082-exec-9 MethodSecurityInterceptor:219 - Secure object: ReflectiveMethodInvocation: public abstract long com.test.management.repositories.orders.OrderRepository.countByDateWithPaymentStatus(java.time.Instant,com.test.management.model.enums.PaymentStatus,long); target is of class [com.sun.proxy.$Proxy360]; Attributes: [[authorize: 'isAuthenticated()', filter: 'null', filterTarget: 'null']]
07/04/2020 15:23:12,495 DEBUG http-nio-8082-exec-9 AffirmativeBased:66 - Voter: org.springframework.security.access.prepost.PreInvocationAuthorizationAdviceVoter@a3c2c4e, returned: 1
07/04/2020 15:23:12,495 DEBUG http-nio-8082-exec-9 MethodSecurityInterceptor:243 - Authorization successful
07/04/2020 15:23:12,495 DEBUG http-nio-8082-exec-9 MethodSecurityInterceptor:256 - RunAsManager did not change Authentication object
07/04/2020 15:23:12,496  WARN http-nio-8082-exec-9 EntityManagerEnabledFilterAspect:34 - Unable to enable filter
07/04/2020 15:23:12,496  WARN http-nio-8082-exec-9 EntityManagerStoreFilterAspect:41 - Unable to enable filter
07/04/2020 15:23:12,496  WARN http-nio-8082-exec-9 EntityManagerStoreFilterAspect:41 - Unable to enable filter
07/04/2020 15:23:12,554 DEBUG http-nio-8082-exec-9 MethodSecurityInterceptor:219 - Secure object: ReflectiveMethodInvocation: public abstract long com.test.management.repositories.orders.OrderRepository.countPendingOrdersByPaymentType(com.test.management.model.enums.PaymentType,java.lang.String); target is of class [com.sun.proxy.$Proxy360]; Attributes: [[authorize: 'isAuthenticated()', filter: 'null', filterTarget: 'null']]
07/04/2020 15:23:12,554 DEBUG http-nio-8082-exec-9 AffirmativeBased:66 - Voter: org.springframework.security.access.prepost.PreInvocationAuthorizationAdviceVoter@a3c2c4e, returned: 1
07/04/2020 15:23:12,555 DEBUG http-nio-8082-exec-9 MethodSecurityInterceptor:243 - Authorization successful
07/04/2020 15:23:12,555 DEBUG http-nio-8082-exec-9 MethodSecurityInterceptor:256 - RunAsManager did not change Authentication object
07/04/2020 15:23:12,555  WARN http-nio-8082-exec-9 EntityManagerEnabledFilterAspect:34 - Unable to enable filter
07/04/2020 15:23:12,555  WARN http-nio-8082-exec-9 EntityManagerStoreFilterAspect:41 - Unable to enable filter
07/04/2020 15:23:12,556  WARN http-nio-8082-exec-9 EntityManagerStoreFilterAspect:41 - Unable to enable filter
07/04/2020 15:23:12,613 DEBUG http-nio-8082-exec-9 MethodSecurityInterceptor:219 - Secure object: ReflectiveMethodInvocation: public abstract java.lang.Object com.test.management.repositories.orders.OrderCustomRepository.save(java.lang.Object); target is of class [com.sun.proxy.$Proxy360]; Attributes: [[authorize: 'isAuthenticated()', filter: 'null', filterTarget: 'null']]
07/04/2020 15:23:12,614 DEBUG http-nio-8082-exec-9 AffirmativeBased:66 - Voter: org.springframework.security.access.prepost.PreInvocationAuthorizationAdviceVoter@a3c2c4e, returned: 1
07/04/2020 15:23:12,614 DEBUG http-nio-8082-exec-9 MethodSecurityInterceptor:243 - Authorization successful
07/04/2020 15:23:12,614 DEBUG http-nio-8082-exec-9 MethodSecurityInterceptor:256 - RunAsManager did not change Authentication object
07/04/2020 15:23:12,706 DEBUG http-nio-8082-exec-9 AuditingHandler:173 - Touched Order(super=ManagementAbstractEntity(id=null, sid=null, createdBy=9b9ef528-a45e-4ce9-b014-32a157507aef, createdDate=2020-04-07T13:23:12.705Z, lastModifiedDate=2020-04-07T13:23:12.705Z, lastModifiedBy=9b9ef528-a45e-4ce9-b014-32a157507aef, version=1), tenant=Tenant(type=OPTICIAN, fullName=test, lastName=Rossi, firstName=Daniele, tenantId=pianetatecno, group=earlybird, remoteAddress=null, partnerCode=null, billingAddress=Via Verdi, billingZipCode=45011, billingCity=Milano, billingDistrict=MI, billingCountry=IT, taxCode=null, vatNumber=01234567891, currency=EUR, landlinePhone=+39021234567, mobilePhone=null, fax=null, email=daniele.Rossi@gmail.com, certifiedEmail=null, language=it, iban=null, swift=null, sdiAccountId=AAA1233, leadSource=null, completed=true, verified=true, bankTransferEnabled=true, enabled=true, avatar=false, userAgent=null, lastLogin=2020-04-07T09:43:25.395Z), plan=Plan(super=ManagementAbstractEntity(id=4, sid=9784bd5a-cb02-11e9-a070-0a43c9b616c2, createdBy=system, createdDate=2019-08-30T08:45:55Z, lastModifiedDate=null, lastModifiedBy=null, version=1), planName=Enterprise, group=earlybird, duration=30, validFrom=2019-01-01T00:00:00Z, validUntil=null, type=ENTERPRISE, price=70.00, maxStorageSize=3221225472, minUsers=5, maxUsers=30, minStores=1, maxStores=9, maxContacts=30000, maxDocuments=10000), users=5, stores=2, paymentType=BANK_TRANSFER, paymentDetails=, paymentStatus=PENDING, paymentResult=null, paymentUrl=null, taxRate=22, amount=350.00, taxAmount=77.00, totalAmount=427.00, creditDays=0) - Last modification at 2020-04-07T15:23:12.705 by Optional[9b9ef528-a45e-4ce9-b014-32a157507aef]
07/04/2020 15:23:12,910  INFO myThreadAsync2 OrderCommunicationBuilder:43 - Sending notification email to daniele.Rossi@gmail.com for order eccb87c1-00a9-4fc2-bec0-99025dce665f
07/04/2020 15:23:12,911 DEBUG myThreadAsync2 FreeMarkerUtils:31 - Searching template for emailPendingOrder.ftlh language it
07/04/2020 15:23:12,913 DEBUG myThreadAsync2 SimpleDriverDataSource:142 - Creating new JDBC Driver Connection to [jdbc:h2:mem:testdb]
07/04/2020 15:23:12,914  INFO myThreadAsync2 EmailQueueDispatcher:192 - Enqueue email in AWS outgoing emails for email: Id null To [ daniele.Rossi@gmail.com, daniele.Rossi@gmail.com, info@test.com,  test@gmail.com]
07/04/2020 15:23:12,915  INFO myThreadAsync2 QueueManager:162 - Sending message to the queue EMAIL_OUT_QUEUE
07/04/2020 15:23:12,962 DEBUG myThreadAsync2 QueueManager:173 - Message sent, id: 150da44d-a192-4695-b8ac-85046e4f5256
07/04/2020 15:23:12,984 DEBUG http-nio-8082-exec-9 HttpEntityMethodProcessor:265 - Using 'application/json', given [application/json, text/plain, */*] and supported [application/hal+json, application/json, application/schema+json, application/json-patch+json, application/merge-patch+json, application/x-spring-data-verbose+json, application/x-spring-data-compact+json, application/json, application/json, application/*+json]
07/04/2020 15:23:12,985 DEBUG http-nio-8082-exec-9 HttpEntityMethodProcessor:91 - Writing [Resource { content: Order(super=ManagementAbstractEntity(id=65, sid=eccb87c1-00a9-4fc2-bec0-99025dce (truncated)...]
07/04/2020 15:23:12,985 DEBUG http-nio-8082-exec-9 PersistentEntityJackson2Module:180 - Serializing PersistentEntity org.springframework.data.jpa.mapping.JpaPersistentEntityImpl@bfca966.
07/04/2020 15:23:12,986 DEBUG http-nio-8082-exec-9 HstsHeaderWriter:169 - Not injecting HSTS header since it did not match the requestMatcher org.springframework.security.web.header.writers.HstsHeaderWriter$SecureRequestMatcher@1dc39113
07/04/2020 15:23:12,988 DEBUG http-nio-8082-exec-9 DispatcherServlet:1131 - Completed 200 OK
07/04/2020 15:23:12,988 DEBUG http-nio-8082-exec-9 ExceptionTranslationFilter:120 - Chain processed normally
07/04/2020 15:23:12,988 DEBUG http-nio-8082-exec-9 SecurityContextPersistenceFilter:119 - SecurityContextHolder now cleared, as request processing completed

Как видите, код OrderCommunicationBuilder выполняется в новом потоке myThreadAsync2. Я не понимаю, почему TenantController ждет OrderCommunicationBuilder#sendEmailPendingOrder перед возвращением. Любая подсказка будет оценена.

...