You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Achilleus Mantzios <rn...@gatewaynet.com> on 2002/03/21 10:23:22 UTC

Servlet wierd behaviour regarding concurrency in tomcat 4.0.1

Hi,
I have seen a strange threading behaviour in catalina engine.
For servlets that
a) Dont implement SingleThreadModel
b) Dont synchronize over resources
c) Dont have service methods synchronized,

the server serves 2 concurrent requests to 2 clients requesting the same URL
sequentially.
Suppose the following servlet is mapped to /servlet/ThreadTest.

When i invoke from 2 clients
http://myserver/servlet/ThreadTest?foo1=bar1&foo2=bar2 and
http://myserver/servlet/ThreadTest?foo2=bar2&foo1=bar1 respectively

the server seems to spawn 2 threads running the service method of the servlet
as expected.

However when a invoke the follwing 2 urls (or in general IDENTICAL URLS)
e.g.

http://myserver/servlet/ThreadTest?foo1=bar1&foo2=bar2 and
http://myserver/servlet/ThreadTest?foo1=bar1&foo2=bar2 respectively

then the threads (thread?) run as if i had synchronized the service method.

This looks like a bug, here is the source of the simple servlet.

The servlet is as follows....
/*****************************************************************/
import javax.servlet.*;
import javax.servlet.http.*;

public class ThreadTest extends HttpServlet {  
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
    }

    protected void processRequest(HttpServletRequest,HttpServletResponse 
response)
    throws ServletException, java.io.IOException {
        response.setContentType("text/html");
        System.out.println("In the begin damnit");
        try {
        Thread.sleep(10000);
        }
        catch (Exception e) {}
    } 

    protected void doGet(HttpServletRequest request, HttpServletResponse 
response)
    throws ServletException, java.io.IOException {
        processRequest(request, response);
    } 
    protected void doPost(HttpServletRequest request, HttpServletResponse 
response)
    throws ServletException, java.io.IOException {
        processRequest(request, response);
    }
}

-- 
Achilleus Mantzios
S/W Engineer
IT dept
Dynacom Tankers Mngmt
tel:    +30-10-8981112
fax:    +30-10-8981877
email:  it@dynacomtm.com
        rnd@gatewaynet.com


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


Re: Servlet wierd behaviour regarding concurrency in tomcat 4.0.1

Posted by Achilleus Mantzios <rn...@gatewaynet.com>.
I see the same results in tomcat 4.0.2
and in jetty 3.1.3-1.

DO I MISS SOMETHING???

Help!!!

Is it ALWAYS that 2 requests for the SAME URI
block????????????

I seem to raise the white flag fellas.

If anybody can shed some light please do.

In specs, discussions i have never seen any
notion of the "URL" as far as concurrent servlet serving threads are 
concerned.

Please HELP!
I am really stuck, and all i wanna know is if this is the supposed
behaviour or not.
Thanx for any one volunteering to share his/her knowledge.

On Thursday 21 March 2002 11:23, Achilleus Mantzios wrote:
> Hi,
> I have seen a strange threading behaviour in catalina engine.
> For servlets that
> a) Dont implement SingleThreadModel
> b) Dont synchronize over resources
> c) Dont have service methods synchronized,
>
> the server serves 2 concurrent requests to 2 clients requesting the same
> URL sequentially.
> Suppose the following servlet is mapped to /servlet/ThreadTest.
>
> When i invoke from 2 clients
> http://myserver/servlet/ThreadTest?foo1=bar1&foo2=bar2 and
> http://myserver/servlet/ThreadTest?foo2=bar2&foo1=bar1 respectively
>
> the server seems to spawn 2 threads running the service method of the
> servlet as expected.
>
> However when a invoke the follwing 2 urls (or in general IDENTICAL URLS)
> e.g.
>
> http://myserver/servlet/ThreadTest?foo1=bar1&foo2=bar2 and
> http://myserver/servlet/ThreadTest?foo1=bar1&foo2=bar2 respectively
>
> then the threads (thread?) run as if i had synchronized the service method.
>
> This looks like a bug, here is the source of the simple servlet.
>
> The servlet is as follows....
> /*****************************************************************/
> import javax.servlet.*;
> import javax.servlet.http.*;
>
> public class ThreadTest extends HttpServlet {
>     public void init(ServletConfig config) throws ServletException {
>         super.init(config);
>     }
>
>     protected void processRequest(HttpServletRequest,HttpServletResponse
> response)
>     throws ServletException, java.io.IOException {
>         response.setContentType("text/html");
>         System.out.println("In the begin damnit");
>         try {
>         Thread.sleep(10000);
>         }
>         catch (Exception e) {}
>     }
>
>     protected void doGet(HttpServletRequest request, HttpServletResponse
> response)
>     throws ServletException, java.io.IOException {
>         processRequest(request, response);
>     }
>     protected void doPost(HttpServletRequest request, HttpServletResponse
> response)
>     throws ServletException, java.io.IOException {
>         processRequest(request, response);
>     }
> }

-- 
Achilleus Mantzios
S/W Engineer
IT dept
Dynacom Tankers Mngmt
tel:    +30-10-8981112
fax:    +30-10-8981877
email:  it@dynacomtm.com
        rnd@gatewaynet.com


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


Re: Servlet wierd behaviour regarding concurrency in tomcat 4.0.1

Posted by Achilleus Mantzios <rn...@gatewaynet.com>.
I see the same results in tomcat 4.0.2
and in jetty 3.1.3-1.

DO I MISS SOMETHING???

Help!!!

Is it ALWAYS that 2 requests for the SAME URI
block????????????

I seem to raise the white flag fellas.

If anybody can shed some light please do.

In specs, discussions i have never seen any
notion of the "URL" as far as concurrent servlet serving threads are 
concerned.

Please HELP!
I am really stuck, and all i wanna know is if this is the supposed
behaviour or not.
Thanx for any one volunteering to share his/her knowledge.

On Thursday 21 March 2002 11:23, Achilleus Mantzios wrote:
> Hi,
> I have seen a strange threading behaviour in catalina engine.
> For servlets that
> a) Dont implement SingleThreadModel
> b) Dont synchronize over resources
> c) Dont have service methods synchronized,
>
> the server serves 2 concurrent requests to 2 clients requesting the same
> URL sequentially.
> Suppose the following servlet is mapped to /servlet/ThreadTest.
>
> When i invoke from 2 clients
> http://myserver/servlet/ThreadTest?foo1=bar1&foo2=bar2 and
> http://myserver/servlet/ThreadTest?foo2=bar2&foo1=bar1 respectively
>
> the server seems to spawn 2 threads running the service method of the
> servlet as expected.
>
> However when a invoke the follwing 2 urls (or in general IDENTICAL URLS)
> e.g.
>
> http://myserver/servlet/ThreadTest?foo1=bar1&foo2=bar2 and
> http://myserver/servlet/ThreadTest?foo1=bar1&foo2=bar2 respectively
>
> then the threads (thread?) run as if i had synchronized the service method.
>
> This looks like a bug, here is the source of the simple servlet.
>
> The servlet is as follows....
> /*****************************************************************/
> import javax.servlet.*;
> import javax.servlet.http.*;
>
> public class ThreadTest extends HttpServlet {
>     public void init(ServletConfig config) throws ServletException {
>         super.init(config);
>     }
>
>     protected void processRequest(HttpServletRequest,HttpServletResponse
> response)
>     throws ServletException, java.io.IOException {
>         response.setContentType("text/html");
>         System.out.println("In the begin damnit");
>         try {
>         Thread.sleep(10000);
>         }
>         catch (Exception e) {}
>     }
>
>     protected void doGet(HttpServletRequest request, HttpServletResponse
> response)
>     throws ServletException, java.io.IOException {
>         processRequest(request, response);
>     }
>     protected void doPost(HttpServletRequest request, HttpServletResponse
> response)
>     throws ServletException, java.io.IOException {
>         processRequest(request, response);
>     }
> }

-- 
Achilleus Mantzios
S/W Engineer
IT dept
Dynacom Tankers Mngmt
tel:    +30-10-8981112
fax:    +30-10-8981877
email:  it@dynacomtm.com
        rnd@gatewaynet.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>