Howard Lee wrote:

> Hi,
>
> I'm new to Servlet, and have a question about its life span. From what I've
> read, servlets get loaded and it stays in web server's memory space. Does
> this mean servlets stay in JVM and never get garbage collected?? I know
> servlets have destroy method, and it gets called when the servlet gets
> garbage collected. So if servlets stay in JVM, these methods will never get
> called? Any help will be greatly appreciated. Thanks!
>

The server has the option to throw out a servlet instance any time it wants to
(after calling the destroy() method).  For instance, it might decide that it's
low on memory and servlet XYZ has not been called for a long time, so it can
free up memory by destroying that instance.  In practice, most current servers
do this only when you are shutting down the server, or if auto-reloading when
a class changes (useful for development) is implemented.

In between calls to init() and destroy() your servlet does stay in memory, but
there is only one object instance -- it is used to handle all requests from
all users that match the URL to which it is mapped.

>
> howard
>

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

Reply via email to