Online Hibernate Training just in Rs. 1000

One week online training in Hibernate ORM framework. Learn Hibernate Framework and enhance your skills. Best Online Hibernate training at 90% discount. Join Now!! Offer is valid Only for limited Period!!! Online Training

Spring 3.2 Asynchronous Request Processing

In this section, you will learn about Asynchronous Request Processing in Spring MVC 3.2.

Ads

Tutorials   
Spring 3.2 MVC insert and retrieve blob from the database The hidden tag The errors tag net.roseindia.dao net.roseindia.service net.roseindia.model net.roseindia.controller Spring 3.2 MVC Hibernate Example Spring 3.2 MVC, Upload File in a specific folder Spring 3.2 MVC Form Handling The textarea tag The options tag The option tag The select tag The radiobuttons tag The radiobutton tag The checkboxes tag mvc:default-servlet-handler Static Resources Configuration View Controllers Configuration View resolvers Spring 3.2 MVC Hello World Example Content Negotiation Configuration Interceptors Configuration using Java or XML Customizing the MVC Java config or XML Namespace MVC Java Config or the MVC XML Namespace Servlet container initialization through code Support for ETag The checkbox tag Autogenerated logical view name through RequestToViewNameTranslator Modification in conventional ModelAndView ControllerClassNameHandlerMapping class for handling convention mapping The password tag The input tag The form tag Form Tag library configuration Customizing the Default Error Page @ExceptionHandler & @ResponseStatus annotation Multipart support for file upload in Spring MVC Themes and Theme resolvers in Spring MVC Locales in Spring MVC ContentNegotiatingViewResolver Redirecting and forwarding to views Chaining of Multiple view resolvers View Resolving through ViewResolver interface Requests Intercepting through a HandlerInterceptor Defining handler methods using @RequestMapping annotation Spring 3.2 Asynchronous Request Processing @RequestMapping annotation for mapping requests @Controller annotation for defining new controller
Ads

Spring 3.2 Asynchronous Request Processing

In this section, you will learn about Asynchronous Request Processing in Spring MVC 3.2.

Before understanding asynchronous request processing, you must be familiar with Servlet 3 async processing feature.

Servlet 3 async processing

 Given below the sequence of events of Servlet 3 async processing :

  • By calling request.startAsync(), you can put ServletRequest in asynchronous mode. Due to this , Servlet and any Filters exits but  response still open , permitting other thread to complete the processing.

  • The request.startAsync() returns AsynContext which can be utilize later to control the further processing. For example, dispatch() method can be utilized to dispatch the request back to the Servlet container.

  • The current DispatcherType, provided by the ServletRequest, can be utilized to differentiate when a Servlet / a Filter is processing the initial request processing thread and when it is processing in an asynchronous dispatch.

Asynchronous Request Processing

Spring 3.2 asynchronous request processing is based on Servlet 3 based asynchronous request processing. Spring 3.2 asynchronous request processing returns java.util.concurrent.Callable and DeferredResult instead of returning a value and bring out value from a separate thread.

When a application requires to return value asynchronously within a thread handled by Spring MVC, a java.util.concurrent.Callable is returned. Given below the example of a controller method returning Callable :

@RequestMapping(method=RequestMethod.POST)
public Callable<String> UploadFile(final MultipartFile file) {

return new Callable<String>() {
public Object call() throws Exception {
// ...
return "anyView";
}
};
}

When a application requires to return value asynchronously from a thread of its own selection, a DeferredResult can be returned.
Given below the example of a controller method returning DeferredResult :

@RequestMapping("/statements")
@ResponseBody
public DeferredResult<String> statements() {
DeferredResult<String> defResult = new DeferredResult<String>();
// Save the defResult in memory
return defResult;
}


// In some other thread...
defResult.setResult(data);

Given below the sequence for Asynchronous Request Processing with Callable :

  • First, a Callable is returned by the Controller.

  • Asynchronous processing starts by the Spring MVC and also for processing in a separate thread, it submits the Callable to a TaskExecutor.

  • The response stays open in spite of the DispatcherServlet and all Filter's exit.

  • The result is created by the Callable and request is dispatch back to the Servlet container by the Spring MVC.

  •  The DispatcherServlet called once again and processing restarts with the asynchronously created result from the Callable.

Given below the sequence for Asynchronous Request Processing with a DeferredResult :

  • First, a DeferredResult is returned by the Controller and it is saved in memory fro further access.

  • Asynchronous processing starts by the Spring MVC .

  • The response stays open in spite of the DispatcherServlet and all Filter's exit.

  • From some thread, the application sets the DeferredResult and request is dispatch back to the Servlet container by the Spring MVC.

  • The DispatcherServlet called once again and processing restarts with the asynchronously created result from the Callable.



Advertisements

Share on Google+Share on Google+

Spring 3.2 Asynchronous Request Processing

Posted on: January 8, 2013 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

Ads
 

Discuss: Spring 3.2 Asynchronous Request Processing  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0

Ads

 

Ads