On Apr 8, 2005 12:15 PM, Matt Raible <[EMAIL PROTECTED]> wrote:
> 
> On Apr 8, 2005, at 1:00 PM, Christine Huang wrote:
> 
> > On Apr 8, 2005 1:40 PM, Craig McClanahan <[EMAIL PROTECTED]> wrote:
> >>
> >> The servlet container is *not* required to leave your load-on-startup
> >> servlet loaded for the entire duration of the webapp's lifetime
> >> (although, in practice, most containers do).  For example, the
> >> container could unload a servlet that it sees isn't being used, or if
> >> it has memory contention issues, or for whatever reason is desired.
> >>
> >> Of course, if you're talking about ActionServlet, it will get reloaded
> >> again on the next request, but that will cause your init() method to
> >> run again -- wasting a whole bunch of time in many cases.
> >>
> >> A ServletContextListener, on the other hand, guarantees that
> >> contextInitialized() will get called at startup time (before any
> >> requests have been processed), and contextDestroyed() will get called
> >> at shutdown time (after the last request), no matter what happens in
> >> between.
> >>
> >> Craig
> >>
> >
> > Craig,
> >
> > Thanks for the information about ServletContextListener. But I wonder
> > what you do to reload updated data from database without restarting
> > using ServletContextListener. Have another action to call it reload()
> > like Matt Riable said?
> 
> Just in case you're interested in some code:
> 
> StartupListener: http://tinyurl.com/3wvk9
> ReloadAction: http://tinyurl.com/6webx
> 
> Note that my StartupListener extends Spring's ContextLoaderListener.
> This is because servlet 2.3 containers do not guarantee listener order
> initialization.  If you're using Spring, I recommend this approach.  If
> not, you don't need to extend anything.
> 

Actually, both 2.3 and 2.4 are quite specfic about calling order --
see SRV.10.3.3 (startup calls in the order of registration, which
means the order of listing in web.xml) and SRV.10.3.4 (shutdown calls
in reverse order of presentation).

Nothing wrong with what Matt suggests, but it shouldn't be necessary
in a compliant container. (AFAICR, Tomcat 4.x and 5.x have always done
this in the order described above.)

> Matt

Craig

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to