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.
Matt
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]