Bo Xu wrote:

(NOTE:  In all of the discussions below, I'm assuming a servlet container that
implements the 2.2 or 2.3 specifications)

>
> so my question is:
> *  what is servlet definition ?

A "servlet definition" is an instance of the <servlet> tag in your web.xml file.
The following example has two servlet definitions, even though both servlets
utilize the same class file (and this will therefore create two instances):

    <servlet>
        <servlet-name>First Servlet</servlet-name>
        <servlet-class>com.mycompany.mypackage.MyServlet</servlet-class>
    </servlet>

    <servlet>
        <servlet-name>Second Servlet</servlet-name>
        <servlet-class>com.mycompany.mypackage.MyServlet</servlet-class>
    </servlet>

Note that, in the above scenario, static variables in the MyServlet class will be
shared between the two instances, but instance variables will not.

Note also that I'm assuming above that MyServlet does *not* implement
SingleThreadModel.  If it does, the number of instances actually created for each
definition can be greater than one -- usually, servers let you configure the
maximum size of the pool but there is no *standard* mechanism for this.  In this
scenario, static variables are still shared across all the instances, but instance
variables (as their name correctly implies) are unique per instance.

>
> *  can I control it with *code/setting Servlet container*?

Not totally.  If your servlet does not implement SingleThreadModel, the number of
instances is totally determined by the number of your <servlet> entries.  If it
does, there is also server configuration involved, and you will have to check the
instructions on your particular server to know how to configure it.

>
> *  can I use *instance field/static class field* to lock my code if my Servlet
> calss

As above, static fields are shared across instances, as long as all the classes are
loaded by the same classloader.  The 2.2 spec requires that the same classloader be
used for all servlets (and the beans they access) that are in the same web
application to be loaded by the same classloader.

If the same servlet is used in more than one web app, statics will be shared
within, but not across, web applications (because different classloaders are used
per application).

>
> *  has more than one servlet definition and so has more than one instance?
>

Yes, as illustrated by the example above.

>
> Thanks very much in advance!   :-)
>
> Bo
> Nov.04, 2000
>

Craig

___________________________________________________________________________
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

Reply via email to