Asynchronous method invocation in Spring Framework

Since Spring 3.0, annotation support for both task scheduling and asynchronous method execution has been added. The post will give a demo of @Async annotation and its uses.

@Service – annotate classes at service layer level.
@Async – put @Async annotation above the method in an asynchronous process.

To define a void async method

To define an asynchronous method which return something. To achieve it, the method shall return a java.util.concurrent.Future object, and the implementation shall return a new AsyncResult object () let’s use Accountclass:

To retrieve the object saved in Future object

Bean Configuration

client

Log output

Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInShare on RedditShare on StumbleUponEmail this to someoneShare on TumblrDigg this

One thought on “Asynchronous method invocation in Spring Framework

  1. Everything is very open with a very clear clarification of the issues. It was definitely informative.

    Thank you for sharing!

Leave a Reply to Jody Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">