title: Use of @Async with @Transactional method springboot
body: <p>I have @async method in my springboot controller which calls service method (async) and does some DB transactions. When this controllers @async method is called multiple times without time delay, it results in org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection </p>
  
  <p>Controller</p>
  
  <pre><code> @PostMapping(value = "/api/sms/sendmsgasync")
    public ResponseEntity&lt;Boolean&gt; sendSMSMessageAsync(@RequestBody MessageRequestDto messageRequestDto) {
  
      final Future&lt;Boolean&gt; booleanFuture = smsService.sendSingleMessageAsync(messageRequestDto, requestContext.getConversationId());
      log.debug("sendSMSMessageAsync {} &lt;&lt;&lt;&lt;", booleanFuture.isDone());
      return ResponseEntity.ok(true);
    }
  </code></pre>
  
  <p>service</p>
  
  <pre><code> @Async
    @Override
    public Future&lt;Boolean&gt; sendSingleMessageAsync(MessageRequestDto messageRequestDto, String convId) {
  
  
      try {
        sendSingleMessage(messageRequestDto, convId);
      }
      catch (BadRequestException | NotFoundException | TwilioException e) {
        LOG.error("Error in sendSingleMessageAsync. Error logged to SMS Gateway db. Exception '" + e.getMessage() + "'", e);
      }
      return new AsyncResult&lt;&gt;(true);
    }
  </code></pre>
  
  <p>which then calls sendSingleMessage method in same service class in which calls NOT transnational methods to do database look up and adding db entry etc.</p>
  
  <p>When this controllers @async method is called multiple times without time delay, it results in </p>
  
  <blockquote>
    <p>org.springframework.transaction.CannotCreateTransactionException:
    Could not open JPA EntityManager for transaction; nested exception is
    org.hibernate.exception.JDBCConnectionException: Unable to acquire
    JDBC Connection at  ...............
    org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:400)
    ... 65 common frames omitted Caused by:
    java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is
    not available, request timed out after 30000ms. at</p>
  </blockquote>
  
  <p>Do I need to add "ThreadExecutor" with service @async method?</p>
  
  <p>I am new to this so any pointers will be helpful</p>