title: How can I run a method Asynchronously with spring?
body: <p>The following code is suppose to work Asynchronously but instead it waits for the Async part to finish and then goes.  How can I make the <code>blah()</code> method run Asynchronously?</p>
  
  <p><strong>spring.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans 
      xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:task="http://www.springframework.org/schema/task"
      xmlns:context="http://www.springframework.org/schema/context"
      xsi:schemaLocation="
          http://www.springframework.org/schema/beans 
          http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
          http://www.springframework.org/schema/task
          http://www.springframework.org/schema/task/spring-task-3.0.xsd
          http://www.springframework.org/schema/context 
          http://www.springframework.org/schema/context/spring-context-3.0.xsd
      "&gt;
  
      &lt;!-- Activates @Scheduled and @Async annotations for scheduling --&gt;  
      &lt;task:annotation-driven /&gt;
  
      &lt;bean id="test"
          class="com.spring.test.Test"&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p><strong>Test.java</strong></p>
  
  <pre><code>@Path("/test")
  public class Test
  {
    @GET
    @Path("/test")
    @Produces("text/plain")
    public String tester()
    {
      return "Running...";
    }
  
    @GET
    @Path("/triggerNew")
    @Produces("text/plain")
    public String triggerNew()
    {
      System.out.println("BEFORE " + new Date() + " BEFORE");
  
      new Process().blah();
  
      System.out.println("AFTER " + new Date() + " AFTER");
      return "TRIGGERED";
    }
  }
  </code></pre>
  
  <p><strong>Process.java</strong></p>
  
  <pre><code>  @Component
      public class Process
      {
        @Async
        public void blah()
        {
          try
          {
            Thread.currentThread().sleep(5000);
          }
          catch (InterruptedException e)
          {
            e.printStackTrace(); 
          }
          System.out.println("NEW THREAD " + new Date() + " NEW THREAD");
        }
      }
  </code></pre>