Results 1 to 3 of 3

Thread: How to make Spring Dispatcher Async?

  1. #1
    Join Date
    Feb 2013
    Posts
    9

    Default How to make Spring Dispatcher Async?

    Hi, is it possible to handle multiple requests at the same time?

    If I execute the following example I see that the requests are queued and not processed in parallel.

    Code:
    @Controller
    @RequestMapping("/foo")
    public class TestController
    {
    
            @RequestMapping(value = "/bar", method = RequestMethod.GET)
            public void test() throws Exception
            {
                    Syso("Sync");
                    Thread.sleep(60 * 1000);
            }
    }
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    
    <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
            version="3.0">
    
            <servlet>
                    <servlet-name>springapp</servlet-name>
                    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
                    <load-on-startup>1</load-on-startup>
            </servlet>
    
            <servlet-mapping>
                    <servlet-name>springapp</servlet-name>
                    <url-pattern>/*</url-pattern>
            </servlet-mapping>
    
    </web-app>
    How to make it async?

    Requerements:
    * Spring 3.2 is ok
    * Tomcat 7 is ok


    Best Regards,
    Christian.

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    Requests are handled in parallel this has nothing to do wth async or not... Requests are handled in paralell until your request handling threadpool runs out of threads... Not sure how many threads you have (default is 5 or 10 like that).
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Feb 2013
    Posts
    9

    Default

    Hi Marten,
    i thought the same.

    But if I access the same RequestMapping twice (in this case /foo/bar), the second request will wait until the first one is finished.

    How to handle that?

    Best Regards,
    Christian.

    Edit:
    Also the parameters should be the same (in this case, no parameter)
    Last edited by d0x; Mar 7th, 2013 at 07:32 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •