Announcement Announcement Module
No announcement yet.
Spring Async 3.2 Tomcat Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Async 3.2 Tomcat


    I've done some tests with the spring mvc's async functionality and it doesn't work as expected. The tests have been done with the spring-mvc-showcase application and deployed on Tomcat 7.0.34.

    For simplicity I've limited the number of Tomcat's threads to 5:

    <Connector connectionTimeout="20000" maxThreads="5" minThreads="5" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
    The service "/async/callable/response-body" returns a callable and another thread (managed by Spring MVC, not Tomcat) executes the call method. This method sleeps for 2 seconds and returns a String.

    public @ResponseBody Callable<String> callable() {
    	return new Callable<String>() {
    		public String call() throws Exception {
    			return "Callable result";
    If I do 10 requests to "/async/callable/response-body" path in less than 2 seconds, all the requests should be attended by Tomcat's threads because they don't execute the sleep method. If have understood correctly, the Spring managed threads would be sleeping and Tomcat's threads ready to receive more requests.

    However in the tests I've done, the last 5 requests are queued in Tomcat until the first five requests are completed.

    Have I missed something?

    Thanks in advance.

  • #2
    Make sure you have async enabled on the servlet else it will be a normal request.

    Edit: Must have been blinded by the other samples, Callable should work as well. As stated above make sure you have async enabled on the DispatcherServlet.
    Last edited by Marten Deinum; Jan 28th, 2013, 08:27 AM. Reason: Callable should work as well as DeferredResult.


    • #3
      The DispatcherServlet is configured correctly as you can see in the code below:

      It's the last version of spring-mvc-showcase and I've only changed the time to sleep. I wonder if I should configure something in Tomcat to get this work, but I don't think so.


      • #4

        I've done the same test with another application (spring-mvc-chat) and I've got the same result.

        With Tomcat limited to 5 threads, after 5 clients connected to the chat all Tomcat threads are busy and the server doesn't respond.


        • #5
          Hi again,

          I've used the NIO connector instead of the default and now the server does process all the request concurrently.

          <Connector connectionTimeout="20000" maxThreads="5" minThreads="5" port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol" redirectPort="8443"/>
          However, I thought that it wasn't necessary to change the connector to free Tomcat's threads with Servlet 3.0. Have I missunderstod something?