You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Byrom Robert-LRB005 <Ro...@invisix.com> on 2001/08/11 14:55:25 UTC
multi threading in tomcat
hi,
firstly, congrads. to an excellant product , tomcat is certainly the best servlet/jsp container we've used in our company and is second to none.
I hope someone invlolved in the tomcat development can help me here. I'm working on a project which makes heavy use of tomcat and I need to find out a little about the inner workings of its 'engine'. I've looked through some of the source code and the mail archives but so far I cant really find what I'm looking for. In a nutshell, I'd like to find out how the tomcat server deals with concurrent requests. Are requests to tomcat queued or does each request have a unique thread of execution. In the later case, is it necessary to make your application thread safe while using tomcat as a front end?
I hope someone can advise.
thanks in advance
rob.
RE: multi threading in tomcat
Posted by "Craig R. McClanahan" <cr...@apache.org>.
On Sat, 11 Aug 2001, Rob S. wrote:
> > and I need to find out a little about the inner workings of its
> > 'engine'. I've looked through some of the source code and the
>
> -> ^^^^^^ hahaha! I can picture Chris Farley putting finger "quotes" around
> that word. "I might not use "silverware" or "take baths" =) Anyway...
>
> > each request have a unique thread of execution. In the later
> > case, is it necessary to make your application thread safe while
> > using tomcat as a front end?
>
> Actually, the question you're asking is irrespective of the container you're
> running, it's part of how JSPs and servlets work. You can either have them
> accessible concurrently (the default) or not, by setting a <%@ page %>
> attribute in JSP or having your servlet implement the SingleThreadModel
> marker.
>
Note: SingleThreadModel does *not* solve all of your thread safety
concerns, because it is still easy to have multiple requests accessing the
same session. Therefore, I recommend that it not be used - newbies should
learn how to do it right the first time.
> - r
>
>
Craig
RE: multi threading in tomcat
Posted by "Rob S." <rs...@home.com>.
> and I need to find out a little about the inner workings of its
> 'engine'. I've looked through some of the source code and the
-> ^^^^^^ hahaha! I can picture Chris Farley putting finger "quotes" around
that word. "I might not use "silverware" or "take baths" =) Anyway...
> each request have a unique thread of execution. In the later
> case, is it necessary to make your application thread safe while
> using tomcat as a front end?
Actually, the question you're asking is irrespective of the container you're
running, it's part of how JSPs and servlets work. You can either have them
accessible concurrently (the default) or not, by setting a <%@ page %>
attribute in JSP or having your servlet implement the SingleThreadModel
marker.
- r
Re: multi threading in tomcat
Posted by "Craig R. McClanahan" <cr...@apache.org>.
On Sat, 11 Aug 2001, Byrom Robert-LRB005 wrote:
> hi,
>
> firstly, congrads. to an excellant product , tomcat is certainly the
> best servlet/jsp container we've used in our company and is second to
> none.
>
> I hope someone invlolved in the tomcat development can help me here.
> I'm working on a project which makes heavy use of tomcat and I need to
> find out a little about the inner workings of its 'engine'. I've
> looked through some of the source code and the mail archives but so
> far I cant really find what I'm looking for. In a nutshell, I'd like
> to find out how the tomcat server deals with concurrent requests. Are
> requests to tomcat queued or does each request have a unique thread of
> execution. In the later case, is it necessary to make your application
> thread safe while using tomcat as a front end?
>
The precise details depend on which version of Tomcat you're talking
about. Here's how it works in Tomcat 4:
* A single thread running HttpConnector is listening on whatever
TCP/IP socket (say, 8080).
* When an incoming socket connection is accepted, it is handed off
to an HttpProcessor running on another thread (up to a configurable
maximum number of threads) while the connector thread goes back
and waits for another incoming connection.
Thus, each request runs on its own thread, and it is entirely legal to
have multiple threads running through the same servlet instance at the
same time. Therefore, it is *absolutely* required that you make your
servlets thread safe, and this applies to *any* servlet container (not
just Tomcat).
For an understanding of the requirements that all servlet containers must
satisfy, you should really read the Servlet Specification, which you can
download from <http://java.sun.com/products/servlet/download.html>. The
chapter on Servlets describes the lifecycle and instance issues for you.
However, any questions on how to make your applications themselves thread
safe belongs on the TOMCAT-USER list, not here -- this list is focused on
those developing Tomcat itself.
> I hope someone can advise.
>
> thanks in advance
>
> rob.
>
Craig