tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Eisner <cra...@Glue.umd.edu>
Subject Re: Tomcat & SingleThreadModel?
Date Thu, 25 May 2000 15:48:10 GMT

I have a question about the Servlet service() method.
If you look at the docs: 
 
    http://java.sun.com/j2ee/j2sdkee/techdocs/api/javax/servlet/SingleThreadModel.html

    public interface SingleThreadModel

    Ensures that servlets handle only one request at a time. This interface
    has no methods.
    
    If a servlet implements this interface, you are guaranteed that no two
    threads will execute concurrently in the servlet's service method. The
    servlet container can make this guarantee by synchronizing access to a
    single instance of the servlet, or by maintaining a pool of servlet
    instances and dispatching each new request to a free servlet.
    
    If a servlet implements this interface, the servlet will be thread safe.
    However, this interface does not prevent synchronization problems that
    result from servlets accessing shared resources such as static class
    variables or classes outside the scope of the servlet.

Now, what is the relation between the Servlet service() method, and
the HttpServlet doGet() method?  Does SingleThreadModel's gaurantee
of synchronization on service() imply any such gaurantee for doGet()?

-David


On Thu, 25 May 2000, Jim Rudnicki wrote:

> Note this snip from the servlet spec:
> 
> In the case of a servlet that implements the SingleThreadModel interface,
> the servlet container
> may instantiate multiple instances of that servlet so that it can handle a
> heavy request load while
> still serializing requests to a single instance.
> 
> The key word is "may instantiate".  That does not exclude that the server
> can simply block the second request until the first completes, which is just
> what you saw.  The more I hear about SingleThreadModel, the less it seems to
> really help.  You could run your servlet on another engine and it could
> behave different--that'd be fun.
> 
> Jim
> 
> ----- Original Message -----
> From: "Christoph Mack" <C.Mack@austria.eu.net>
> To: <tomcat-user@jakarta.apache.org>
> Cc: <ssi@austria.eu.net>
> Sent: Wednesday, May 24, 2000 8:29 AM
> Subject: Tomcat & SingleThreadModel?
> 
> 
> > Hello!
> >
> > I have Tomcat 3.1 installed on a x86 SuSE 6.3 Linux. I implemented the
> > following very simple servlet:
> >
> > import java.io.*;
> > import javax.servlet.*;
> > import javax.servlet.http.*;
> >
> > public class Loop extends HttpServlet
> >        implements SingleThreadModel
> > {
> >     int global;
> >
> >     public void doGet(HttpServletRequest req,
> >                       HttpServletResponse res)
> >            throws ServletException, IOException
> >     {
> >         int j;
> >         res.setContentType("text/html");
> >         PrintWriter out = res.getWriter();
> >         for(j=0;j<1000000;j++) {
> >           out.println(global++);
> >         }
> >     }
> > }
> >
> > Next I startet two WebBrowsers to connect to my servlet. I expected
> > Tomcat to create two servlet instances (one for each GET-reqest) and
> > thought output will be generated and displayed concurrently.
> > But what really happened is that the second request was obviously NOT
> > served concurrently. The second WebBrowser started to display data AFTER
> > the first WebBrowser finished.
> > What went wrong???
> >
> 
> 
> --------------------------------------------------------------------------
> To unsubscribe, email: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commmands, email: tomcat-user-help@jakarta.apache.org
> 
> 

-----------------------------------------------------
David Eisner            | E-mail: cradle@eng.umd.edu |
CALCE EPSC              | Phone:  301-405-5341       |
University of Maryland  | Fax:    301-314-9269       |
-----------------------------------------------------


Mime
View raw message