Announcement Announcement Module
Collapse
No announcement yet.
How to make Spring Dispatcher Async? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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).

    Comment


    • #3
      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, 07:32 AM.

      Comment

      Working...
      X