Evan J wrote:
On 3/30/07, David Smith <[EMAIL PROTECTED]> wrote:
Quoting the spec here (SRV.2.1 of servlet spec 2.4):
"The handling of concurrent requests to a Web application generally
requires that the Web Developer design servlets that can deal with
muiltiple threads executing within the service method at a particular
time.
"Generally the Web container handles concurrent requests to the same
servlet by concurrent execution of the service method on different
threads."
That right there suggests strongly that you should avoid class instance
variables.
On the thread front, the threads I believe are created by the connectors
to handle incoming requests. Connector threads aren't tied to any
specific webapp or servlet. They call the appropriate method of a
servlet and pass in a HttpServletRequest and HttpServletResponse object.
--David
David,
Thank you for your response. A further investigation of Tomcat source
code reveals that, indeed, the servlet definition class such as
`org.apache.catalina.core.StandardWrapper.java' implements a singleton
design in creation of each servlet (in allocate() method). Unless of
course, servlet implements a single thread model, in that case, a
stack structure is used to handle pool of such servlet instances.
What I am still inclined to figure out is at what location(s) does the
container creates threads to handle servlet requests/responses? I've
looked in `org.apache.catalina.core/connector' packages in vein. Does
anyone aware of such detail?
Thank You
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
I wouldn't get too hung up on the internals of tomcat here. You should
remember servlet engines can be implement the spec in any way they see
fit. They are only required to comply with the spec. Anything not
spelled out there is subject to interpretation.
Suffice it to say servlets in and of themselves should be as stateless
as possible as various threads call on their methods. Stuff that
persists for the life of the request, session, or application are stored
as attributes of the request, session, or servletContext respectively.
I'll step back here and let a tomcat developer explain the internals of
tomcat. I've only ever had a cursory look at the tomcat internal source
code. I do know the threads aren't created per request -- they are
pooled and the pool creates/drops threads as necessary. Everywhere else
they are just borrowed, used, and returned.
--David
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]