Hello Pradeep,

> Can someone tell me, when does the web container destroys the servlet object?
>
> More specifically, are the servlet objects destroyed whenever the container
> goes down? Or, is it that the container can destroy the object and recreate
> it periodically.
>
> According to the specification, there must be one and only one instance of a
> servlet.

Others on the alias pointed to some good information, but I wanted to
elaborate....

Yes, the Web container can destroy a servlet *whenever* it chooses and it
*must* destroy all servlets on an orderly shutdown (no such guarantee if
the container crashes).  The key point is that:  You (as a servlet developer)
cannot know *when* or *how often* a servlet is destroyed.

Now, as you mentioned the spec declares that Web container must keep *at
most* one servlet instance per servlet definition (which is declared in the
deployment descriptor).  [The only caveat is that if the servlet class
implements SingleThreadModel, then the container might create a pool of
instances.  But because STM is a bad idea, it is safe to assume the "one
and only one servlet instance" model.]

Notice that I said "at most one servlet instance".  It is quite possible
that the container will not load a servlet instance until it is actually
needed.  [You can force the container to pre-load servlet instances in
the deployment descriptor.]

What is also important are the details about constraints that must be
satisfied for the container to destroy a servlet instance.  The primary
requirement is that there are no requests currently being processed by
the servlet instance.  In other words, if the container wishes to delete
servlet X, but there are several requests being processed by X, then the
container must wait until all of these requests have been completed.
However, I container may choose to block any new requests (typically,
by sending a 404 message, but that is vendor-specific).

Another constraint is that the container cannot create a new instance for
servlet X, until the previous instance has completed execution of the
destroy method.

I hope this discussion was useful.

Regards,
Bryan


+-----------------------------------+------------------------------------------+
| Bryan Basham                      | What we are today comes from our         |
| Java Courseware Developer         | thoughts of yesterday, and our present   |
| Sun Services                      | thoughts build our life of tomorrow:     |
|   Phone: 1-303-272-8766 (x78766)  |    our life is the creation of our mind. |
|  E-mail: [EMAIL PROTECTED]     | If a man speaks or acts with a pure      |
| Address: 500 Eldorado Blvd        | mind, joy follows him as his own shadow. |
|          MailStop: UBRM05-135     |  -- The Dhammapada (verse 2)             |
|          Broomfield, CO 80021     |     (trans. Juan Mascaro)                |
+-----------------------------------+------------------------------------------+

***************************************
SunNetwork 2003 Conference and Pavilion
"An unparalleled event in network computing! Make the net work for you!"

WHEN:  September 16-18, 2003
WHERE: Moscone Center, San Francisco

For more information or to register for the conference, please visit:
http://www.sun.com/sunnetwork

___________________________________________________________________________
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