tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Frank W. Zammetti" <>
Subject Re: Do idle servlets get unloaded/reloaded?
Date Tue, 24 Jan 2006 20:03:09 GMT
Hi Blair,

On Tue, January 24, 2006 2:41 pm, Blair Cooper said:
> I have a servlet running on Tomcat 5.5. If it sits idle for a while and
> then
> I hit it, the init() method gets called again. "autoDeploy" is set to
> false.
> Is this expected behavior?

As per the servlet spec, the container can unload and reload a servlet as
needed.  It is an expected *potential* behavior.  My own personal
experience would indicate it's rare, but you have to design for it.

> If this is expected, shouldn't destroy() get called at some point prior to
> the init()?

I would expect destroy() to get called at some point before init() does a
second time, but I'm not sure if that is a guarantee of the spec.  Seems
like it probably would be though.

> The problem I'm having is that the init() method ends up try to recreate
> objects that where created by a previous call to init(). My destroy()
> method
> would have cleaned up the earlier instances if it had been called. I have
> logging in the destroy() method so I know that it didn't get called.

Implement some sort of check in init() to determine if it has fired
already or not.  A simple static boolean field on the servlet should do
the trick.  So, maybe you have:

private static boolean isInitialized;

Then in init(), you do:

synchronized (isInitialized) {
  if (!isInitialized) {
    // Do initialization tasks.
    isInitialized = true;

> Thanks,
> Blair


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message