java @Asynchronous Methods: not running async

后端 未结 2 1828
[愿得一人]
[愿得一人] 2021-01-22 14:58

I try to get an async process running. Based on this example: http://tomee.apache.org/examples-trunk/async-methods/README.html

But the method addWorkflow(Workflow

2条回答
  •  故里飘歌
    2021-01-22 15:40

    So the normal way would be to have the @Asynchronous method in another bean from the caller method.

    @Stateless
    public class ComputationProcessor {
    
     @Asynchronous
     public Future performComputation {
       return new AsyncResult(null);
     }
    }
    
    @Stateless
    public class ComputationService {
    
     @Inject
     private ComputationProcessor mProcessor;
    
     public void ...() {
       Future result = mProcessor.performComputation();
       ...
     }
    }
    

    As you discovered, it won't work if the @Asynchronous method is in the same bean than the caller.

提交回复
热议问题