See below.

Tony Wiegand wrote:

> Hi,
>
>    I'm having trouble implementing the model 2 design pattern using
>  Weblogic 5.1.   It seems the container is constantly calling
>  destroy on the servlet and re-initializing a new instance.  So any classes
>  or data that I have cached is being erased.
>
>   Looking at the Servlet 2.2 spec I'm not sure if this is problem or not.
>
>    From Servlet 2.2 spec:
>          End of Service
>                    The servlet container is not required to keep a servlet
> loaded for any period of time. A servlet
>                    instance may be kept active in a servlet container for a
> period of only milliseconds, for the lifetime
>                    of the servlet container (which could be measured in
> days, months, or years), or any amount of time
>                    in between.
>
>                    When the servlet container determines that a servlet
> should be removed from service (for example,
>                    when a container wants to conserve memory resources, or
> when it itself is being shut down), it must
>                   allow the servlet to release any resources it is using and
> save any persistent state. To do this the
>                   servlet container calls the destroy method of the Servlet
> interface.
>                   Before the servlet container can call the destroy method,
> it must allow any threads that are
>                   currently running in the service method of the servlet to
> either complete, or exceed a server
>                   defined time limit, before the container can proceed with
> calling the destroy method.
>                   Once the destroy method is called on a servlet instance,
> the container may not route any more
>                   requests to that particular instance of the servlet. If
> the container needs to enable the servlet again, it
>                   must do so with a new instance of the servlet's class.
>                   After the destroy method completes, the servlet container
> must release the servlet instance so
>                   that it is eligible for garbage collection
>
>                         Thanks,
>                         Tony
>

Although the servlet container has the right to create and destroy servlet
instances whenever it wants (as the spec passage you quoted indicates), the ones
I'm familiar with tend not to actually do so unless the application is being shut
down.  It might be worth contacting Weblogic's support list to verify that their
container actually does repeatedly create and destroy the instance, and (if it
does) if there is any way to configure the server to not do this.

Failing that, one approach you could take would be to store the cached information
as servlet context attributes rather than instance variables in the controller
servlet instance.  That way, those objects would survive the shutdown and restart
of the controller servlet.

Craig McClanahan

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to