Wednesday 15 August 2012

java - Spring 3.2 @Async task with return type of Future -


I am trying to implement the spring @ async work in which there is a return type of future, but I really understand Can not do it properly.

  1. How will I benefit from doing this? Will I have a control over my work now, so can I stop it and run it?
  2. Is there any reference implementation that I can do it? The springs source does not provide any.

    edit

    with spring source and spring guideline:

    Even Methods That Can Return a Value Asynchronously However, such methods require a future type return value. It still provides the advantage of asynchronous execution so that the caller can perform other tasks before getting the call (call) on that future.

    And it gives an example:

      @Async Future & lt; String & gt;   

    check out. By using

    @Async allows you to run in a method asynchronously. This means that if it is called (on the spring managed bean), the control is immediately returned to the caller and the code is run in the second thread in the method. The caller receives a future object which is compulsive for current computing and can use it to check that the calculation is ongoing and / or the result is expected.

    It is easy to make such a method. Comment with @async and post the result in asyncResult , as shown in the blog post.

No comments:

Post a Comment