title: Spring Cancel @Async Task
body: <p>I want to be able to cancel a method marked with the <code>@Async</code> annotation by it's future.</p>
  
  <p>I have a Spring method marked with the <code>@Async</code> annotation. This method does some computation, and eventually returns a result. All examples I have seen recommend using the <code>AsyncResult</code> class to return this Future. </p>
  
  <pre><code>@Async
  public Future&lt;String&gt; run() {
      // ... Computation. Minutes pass ...
      return new AsyncResult&lt;String&gt;("Result");
  }
  </code></pre>
  
  <p>I call the following method, from another Component, in the following manner. For example purposes, I wish to immediately cancel this thread: </p>
  
  <pre><code>Future&lt;String&gt; future = component.run();
  future.cancel(true);
  </code></pre>
  
  <p>In this case, the thread will never be cancelled. This is because, looking at the Spring implementation for <code>AsyncResult</code> here: <a href="https://github.com/spring-projects/spring-framework/blob/master/spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncResult.java#L71" rel="noreferrer">https://github.com/spring-projects/spring-framework/blob/master/spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncResult.java#L71</a> , this method doesn't actually do a single thing. It simply returns false, that the thread could not be cancelled. This is my problem. How can I cancel the Thread being created by the <code>@Async</code> method? I have no access to the internal thread being created by Spring - so I have no means myself with which to cancel it, do I?</p>