title: Spring Async is blocking and prevents nested async calls
body: <p>Can anybody tell my is there a way of using the Spring Framework's <code>@Async</code> annotation without blocking / waiting on the result? Here is some code to clarify my question:</p>
  
  <pre><code>@Service
  public class AsyncServiceA {
  
      @Autowired
      private AsyncServiceB asyncServiceB;
  
      @Async
      public CompletableFuture&lt;String&gt; a() {
          ThreadUtil.silentSleep(1000);
          return asyncServiceB.b();
      }
  }
  
  
  @Service
  public class AsyncServiceB {
  
      @Async
      public CompletableFuture&lt;String&gt; b() {
          ThreadUtil.silentSleep(1000);
          return CompletableFuture.completedFuture("Yeah, I come from another thread.");
      }
  }
  </code></pre>
  
  <p>and the configuration:</p>
  
  <pre><code>@SpringBootApplication
  @EnableAsync
  public class Application implements AsyncConfigurer {
  
      private static final Log LOG = LogFactory.getLog(Application.class);
  
      private static final int THREAD_POOL_SIZE = 1;
  
      public static void main(String[] args) {
          SpringApplication.run(Application.class, args);
      }
  
      @Bean
      public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
          return args -&gt; {
              final AsyncServiceA bean = ctx.getBean(AsyncServiceA.class);
              bean.a().whenComplete(LOG::info);
          };
      }
  
      @Override
      @Bean(destroyMethod = "shutdown")
      public ThreadPoolTaskExecutor getAsyncExecutor() {
          final ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
          executor.setCorePoolSize(THREAD_POOL_SIZE);
          executor.setMaxPoolSize(THREAD_POOL_SIZE);
          executor.initialize();
          return executor;
      }
  
      @Override
      public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
          // omitted
      }
  }
  </code></pre>
  
  <p>When I run the application the executor goes through calling <code>AsyncServiceA.a()</code> and leaves, but it still holds the thread from the pool waiting on the <code>CompletableFuture.get()</code> method. Since there is just a single thread in the pool the <code>AsyncServiceB.b()</code> cannot be executed. What I'm expecting is that thread to be returned to the pool after it executes the <code>AsyncServiceA.a()</code> and then be available to execute the <code>AsyncServiceB.b()</code>. </p>
  
  <p>Is there a way to do that?</p>
  
  <p>Note 1: I've tried with <code>ListenableFuture</code> also but the result is the same.</p>
  
  <p>Note 2: I've <strong>successfully</strong> did it manually (without the <code>@Async</code>) by giving the executor to each method like so:</p>
  
  <p>AsyncServiceA</p>
  
  <pre><code>public CompletableFuture&lt;String&gt; manualA(Executor executor) {
      return CompletableFuture.runAsync(() -&gt; {
          LOG.info("manualA() working...");
          ThreadUtil.silentSleep(1000);
      }, executor)
              .thenCompose(x -&gt; asyncServiceB.manualB(executor));
  }
  </code></pre>
  
  <p>AsyncServiceB</p>
  
  <pre><code>public CompletableFuture&lt;String&gt; manualB(Executor executor) {
      return CompletableFuture.runAsync(() -&gt; {
          LOG.info("manualB() working...");
          ThreadUtil.silentSleep(1000);
      }, executor)
              .thenCompose(x -&gt; CompletableFuture
                      .supplyAsync(() -&gt; "Yeah, I come from another thread.", executor));
  }
  </code></pre>
  
  <p>Here is the <code>ThreadUtil</code> if someone was wondering.</p>
  
  <pre><code>public class ThreadUtil {
  
      public static void silentSleep(long millis) {
          try {
              Thread.sleep(millis);
          } catch (InterruptedException e) {
              throw new RuntimeException(e);
          }
      }
  }
  </code></pre>
  
  <p><strong>Update</strong>: Added issue for non-blocking Async annotation <a href="https://jira.spring.io/browse/SPR-15401" rel="noreferrer">https://jira.spring.io/browse/SPR-15401</a></p>