Mastering_the_Object
Mastering_the_Object

Reputation: 1033

Tomcat JSPs appear to be running serially (instead of in parallel) - what am I missing?

I have the following simple JSP running in Tomcat 7. Nothing else in the container and no web.xml. I hit the url http://localhost:8090/test/test.jsp three times in quick succession from my browser in three separate tabs (Chrome).

<%@ page import="java.util.Date" %>
<%
    out.println("Hello there dude");
    System.out.println("Hello there my friend "+ new Date() +"
                "+Thread.currentThread().getName());
    try {
        Thread.sleep(5000);
    } catch(Exception e)
    {
        e.printStackTrace();
    } 
%>

`

When I run it in Tomcat 7 or any other version of Tomcat, the JSP servlet will block multiple requests and I get output like this in the console.

Hello there my friend Thu Feb 02 19:31:35 MST 2012 http-bio-8090-exec-1
Hello there my friend Thu Feb 02 19:31:40 MST 2012 http-bio-8090-exec-3
Hello there my friend Thu Feb 02 19:31:45 MST 2012 http-bio-8090-exec-4

If you examine the times, you will see the JSP servlets are executing serially. I started them all at the same time, so I believe they should finish within a second of each other, but the subsequent requests don't start until the previous request has completed. These are start times above and the browser will hang on the last request for 15 seconds. The JSP requests should execute in parallel if I understand the spec as I am not asking for single threaded behavior.

Interesting enough, Tomcat is allocating different threads as shown above, but they are definitely executing serially. It's like the container won't release a new JSP servlet thread to process until the proceeding request is finished. We run Webservices all day and they seem to execute in parallel just fine.

I am running on a multi-core Windows box and the default out of the box Tomcat configuration which has 200 threads available.

Upvotes: 3

Views: 1231

Answers (1)

EMS
EMS

Reputation: 188

It does seem likely that this is actually a case of the browser blocking the requests, rather than Tomcat blocking threads. I just tried the same code on my Tomcat 7 install, and ran wget localhost:8060/ThreadTest/ & three times in rapid succession, and all three finished within 1 second of each other.

Upvotes: 3

Related Questions