Nic Ferrier wrote:
> >>> Milt Epstein <[EMAIL PROTECTED]> 24-May-00 2:36:10 PM >>>
>
> >OK. But then how is this reconciled with what I said about the
> spec
> >requiring that only one instance be created in most cases? Is the
> >correct interpretation that only one instance be created unless
> there
> >are multiple mappings *or* SingleThreadModel is implemented?
>
> Only one instance should be created unless there are multiple
> mappings.
>
> In fact the mapping->servlet class should be considered an instance
> binding.
>
> If the spec doesn't currently say so then it needs to be changed. I
> will go through it and make sure that it feeds into the current JSR.
>
What the spec does is distinguish between two concepts that I believe are
getting confused here.
A servlet *definition* is the occurrence of a <servlet> element in your web.xml
file. As Nic pointed out, there is one instance of a servlet class per servlet
definition (unless it implements SingleThreadModel -- see below), even if the
same class file is used. Thus, if you want to use the same servlet class more
than once with different initialization parameters, you create more than one
servlet definition -- and therefore end up with more than one instance.
A servlet *mapping* is the occurrence of a <servlet-mapping> element in your
web.xml. The purpose of a mapping is to tell the servlet container how to read
a request URI and select the appropriate servlet definition to execute. You
can have as many mappings as you like for a particular definition -- but they
all select the same instance.
For example, you can make both lower-case and upper-case versions of the "JSP"
extension map to your JSP servlet like this (assuming that the servlet name is
"jsp" like it is in Tomcat):
<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>*.JSP</url-pattern>
</servlet-mapping>
These both name the same servlet definition, so they both map to the same
servlet instance (since the JSP servlet does not implement SingleThreadModel).
>
> The SingleThreadModel issue is different.
>
> The spec requires that there be only one instance per mapping because
> to do otherwise would break SingleThreadModel (no bad thing in my view
> but there we are...).
>
> If you had two instances mapped to a single path how would you
> synchronize them?
>
> With one instance mapped to a path it's easy:
>
> synchronized(servletobject)
> {
> servletobject.service(request,response);
> }
>
Servlet containers that support multiple instances of an STM servlet do so by
maintaining a pool of available instances -- much like a database connection
pool keeps a set of connections available. When a request comes in, an
instance is allocated from the pool and used for the request, and then
returned. But, the instances stuff is related to servlet definitions, not
servlet mappings.
It's important to be precise about the words we use ... otherwise everyone is
going to get even more confused. In a case like this, using the words as they
are used in the spec makes the most sense.
>
> Nic Ferrier
>
>
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