Jeffrey DeLeo wrote:

> I'm currently using the following architecture to initialize
> application-wide resource (such as database connection pools):
>
> Define a servlet that in:
>
>   init() - creates resources, and stores them as attributes on the servlet
> context
>
>   destroy() - removes these attributes from the servlet context. As this is
> the only reference to
>     them, they are then unavailable, and will eventually be garbage collected.
>
> Different JSP pages can then grab these resources as application-scope beans.
>
> Reading the Servlet specification, it says the Servlet container can unload
> a servlet at any time - this means that my global resources will suddenly
> become unavailable! Is this correct?
>

If you use the code described above, yes that is correct.

>
> How are other people dealing with the problems of
> initialization/destruction of application-scope resources?
>

The servlet specification is currently missing a clean, portable, way to deal with
"application start" and "application stop" events.  IMHO this is a high priority
for the next spec version.

The alternative that has worked best for me is to use a servlet container that does
*not* arbitrarily unload servlets -- such as the JSWDK or the current version of
Jakarta Tomcat -- or does so when you turn on the "autoreload" feature, like Apache
JServ.  But that's not always an option.  Another approach would be to call a
special servlet at shutdown time that does the removals, and make sure it is never
called at any "normal" time.

Craig McClanahan

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html

Reply via email to