Kevin Jones wrote:
> Section 3.2 of the August Servlet 2.2 spec (PR1) says that 'By default,
> there must be only one instance of a servlet class per servlet definition in
> a container' - in the past there's been discussion on this list (and the JSP
> list) about threading. Now, modulo SingleThreadModel (which the spec talks
> about in the next paragraph) my understanding was that a servlet engine
> could (and often/always did) instantiate a pool of servlets (within the same
> container) to provide a degree of load balancing - this statement seems to
> stop that. Am I reading this correctly or am I missing something?
>
> Kevin
>
The "by default" case is the non-SingleThreadModel case. In such an
environment, creating more than one instance of a servlet in the same container
doesn't help you any, because there is already no limit on the number of
threads that can be active in the one-and-only instance of that servlet.
Previous versions of the spec were silent on the number of instances were
created for a non-SingleThreadModel (non-STM for short) servlet, even though
(as a practical matter) servlet engines only created one. Now that this is
mandated, servlet authors can count on it, and can use instance variables in
the class to share state information across requests -- as long as it is not
required outside of the servlet.
For example, consider a simple hit counting servlet. The natural place to
store the counter would be an instance variable in the servlet class (suitably
initialized in the init() method and saved to disk in the destroy() method).
But, if the servlet engine was allowed to create more than one instance, this
counter would not be accurate! As of 2.2, servlet authors can count on what
has been standard practice all along -- only one instance of a non-STM servlet
will be created in a container.
SingleThreadModel servlets, on the other hand, are often operated in pools.
For example, if you have a pool size of five, that means five (and only
five) simultaneous requests can be handled, because the servlet container
promises that only one request will be in progress in any one instance at a
time. The sixth simultaneous request will have to wait. In most servlet
engines, the minimum and maximum instances are configurable, so you can tune
the size of the pool to your needs.
Craig McClanahan
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html