title: java @Asynchronous Methods: not running async
body: <p>I try to get an async process running. 
  Based on this example: <a href="http://tomee.apache.org/examples-trunk/async-methods/README.html" rel="nofollow">http://tomee.apache.org/examples-trunk/async-methods/README.html</a></p>
  
  <p>But the method <code>addWorkflow(Workflow workflow)</code> will only return when the code in <code>run(Workflow workflow)</code> is fully completed.</p>
  
  <p>Then when it returns and <code>result.get();</code> is called I'll get the exception: </p>
  
  <blockquote>
    <p>Caused by: java.lang.IllegalStateException: Object does not represent an acutal Future</p>
  </blockquote>
  
  <p>Any suggestion what I'm missing?</p>
  
  <pre><code>@Singleton
  public class WorkflowProcessor {
  
  @EJB
  private  WorkflowManager workflowManager;
  
  private final static Logger log = Logger.getLogger(WorkflowProcessor.class.getName());
  
  
  
  public void runWorkflows(Collection&lt;Workflow&gt; workflows) throws Exception{  
      final long start = System.nanoTime();
      final long numberOfWorkflows = workflows.size();
      Collection&lt;Future&lt;Workflow&gt;&gt; asyncWorkflows = new ArrayList&lt;&gt;();
  
      for(Workflow workflow : workflows){
          Future&lt;Workflow&gt; w = addWorkflow(workflow);
          asyncWorkflows.add(w);
      }    
      log.log(Level.INFO, "workflow jobs added {0}", new Object[]{numberOfWorkflows});
      for(Future&lt;Workflow&gt; result : asyncWorkflows){
         result.get();
      }
  
      final long total = TimeUnit.NANOSECONDS.toSeconds(System.nanoTime() - start);
      log.log(Level.INFO, "WorkflowProcessor-&gt;runWorkflows {0} workflows completed in:{1}", new Object[]{numberOfWorkflows, total});
  
  }
  
  @Asynchronous
  @Lock(LockType.READ)
  @AccessTimeout(-1)
  private Future&lt;Workflow&gt; addWorkflow(Workflow workflow){
  
      run(workflow);
  
      return new AsyncResult&lt;Workflow&gt;(workflow);                
  }
  
  
  private void run(Workflow workflow){
      this.workflowManager.runWorkflow(workflow);
  }
  </code></pre>