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

Evan J wrote:

Hi,

I am new to servlets and web container. From what I have read so far,
I've gotten an impression that the web containers, in this case
Tomcat, create only _one_ instance of each particular servlet upon
start/[re]deployment of a web application. Any request to such servlet
would cause a container to spawn a thread that would call upon this
servlet instance's methods (service()...).

My first question is, that under any circumstances, does the container
create a second instance of a servlet (obviously we are talking about
a servlet with a unique registered name not all the servlets in the
context)? I tried to verify this by placing `this' in a Hashtable
during doGet/Post() call to see whether the Container creates a new
one which apparently doesn't but I just want to make sure if my
assumption is correct. If that's correct then it does not matter the
servlet's variable be an instance variable or a class variable.

Another question that arises (relating to the first question), does
every newly created thread with the help of Container get accessed to
that single servlet instance and pass the request/response objects to
the servlet?

Wanting to dig deeper into details, and I know this may not be an
appropriate mailing list, but where does Tomcat container management
actually create these threads? What java file to be more specifically?

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]



---------------------------------------------------------------------
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