On Tue, 2008-07-01 at 08:46 +0200, Leon Rosenberg wrote:
> Hello Frederic,
> 
> unless you are using the SingleThreaded Model (and you shouldn't)
> tomcat does no such thing.

There's no way I could be doing any such thing unknowingly, such as it
being the default, right?

> I assume the best way is to show us your servlet code, or to check for
> synchronized blocks in it.

The dispatch code is quite simple:

protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
    try {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
    } catch(UnsupportedEncodingException e) {
        throw(new AssertionError(e));
    }
    try {
        if(req.getPathInfo().equals("/")) {
            redirect(req, resp, "/ls");
        } else if(req.getPathInfo().equals("/ls")) {
            req.setAttribute("db", load());
            Thread.sleep(10000);
            getServletContext().getNamedDispatcher("index")
                .forward(req, resp);
        } else if(req.getPathInfo().equals("/adm")) {
            req.setAttribute("db", load());
            Thread.sleep(10000);
            getServletContext().getNamedDispatcher("admin")
                .forward(req, resp);
        } else if(req.getPathInfo().equals("/css")) {
            getServletContext().getNamedDispatcher("style")
                .forward(req, resp);
        } else {
            error(req, resp, 404, "Resource not found");
        }
    } catch(Exception e) {
        log("Caught exception", e);
        error(req, resp, 500, "Internal error");
    }
}

You can see the Thread.sleep calls that I mentioned. The `load' function
does no synchronization whatsoever.

I followed Steffen Heil's advice on sending a SIGQUIT to Tomcat to get
the thread dump, and the results are as follows:

When I'm running one request to "/ls" and one to "/adm" simultaneously,
there are indeed two threads in the doGet function above, one sleeping
on the first Thread.sleep call and one on sleeping on the other.

When, on the other hand, I'm running two requests to "/ls"
simultaneously, there is only one thread from the pool in the doGet
function. All other threads in the pool are sleeping with the following
stack trace:

   java.lang.Thread.State: WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        - waiting on <0x95401098> (a org.apache.tomcat.util.threads.ThreadPool
$ControlRunnable)
        at java.lang.Object.wait(Object.java:485)
        at org.apache.tomcat.util.threads.ThreadPool
$ControlRunnable.run(ThreadPool.java:656)
        - locked <0x95401098> (a org.apache.tomcat.util.threads.ThreadPool
$ControlRunnable)
        at java.lang.Thread.run(Thread.java:619)

Except one, which is trying to accept a connection from the listening
socket, but that seems to be the idle condition (it does that when I'm
running the dual requests to "/ls" and "/adm" as well).

By the way, this is Tomcat 5.5.17. Might that matter?

Fredrik Tolf



---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to