TwelveEighty <> said:
>On Dec 2, 12:42 pm, Juha Laiho <Juha.La...@iki.fi> wrote:
>>
>> Another way to achieve the same would be to write and declare
>> a ServletContextListener to handle the startup. This would have
>> the added benefit of also being able to shut down the "external"
>> server cleanly when Tomcat is being shut down.
>>
>
>After Arne's post, I started looking into this and I noticed that
>there is also an init() and destroy() method on the HttpServlet
>itself. What would be a better approach, to use the
>ServletContextListener, or use the init() and destroy() methods for
>startup and shutdown of the "external" server?
I took a quick glance at the Servlet Specification, and the language
lawyer in me found at least one potential issue; the servlet container
is free to release any servlet that is not currently running, and I
didn't see any mention about load-on-startup servlets being any
exception to this. So, a servlet marked load-on-startup will be loaded
on context startup - and thus, its init() will be called. However,
unless I missed something, the container is also free to unload the
servlet on the next second, and at that point would call destroy()
on it.
Realistically, I consider the above to be highly unexpected behaviour,
and haven't seen any container do it. But as long as the spec allows
it, you should consider it a valid scenario.
--
Wolf a.k.a. Juha Laiho Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)
|