I asked this because I am trying to understand the behaviour, not only know some
base facts.
Yes, a servlet in memory when not used is passive and uses not much memory etc.
But I would like to understand the mechanism of cleaning up.
Sessions are invalidated more or less automatically. That means that a shopping
cart object (, with user related items stored in a vector on the shoppping cart)
will be garbage collected after it is not used for some time. This mechanism
doesn't work perfect on Win2k/IIS. I worked around it by checking all
session-related objects on each hit and invalidating them manually.
My servlets are all using database connections.
At some point I may decide to close one of the database connections.
For that I need to really understand the mechanism of garbage collecting servlet
instances.
Maybe you can advise a good book on that ?
Java Servlet Programming from O'Reilly does give answers on initialising, but
not enough about destroying.
Nico
--
Remember that only a single instance of the servlet is created the first
time it is called. It is up to tomcat to decide weather to call that
servlet's destroy() method. I personally prefer that the servlet is just
waiting for a request rather then being destroyed frequently as your
performance will be better and servlets are idle while not in use. The
effect on memory or cpu usage is extremely low (insignificant?). Your
individual sessions will clean up after themselves.
I have been closely monitoring this on a Linux server and have found
everything to work perfectly. You can try starting tomcat with
the -verbose:gc Option and watch the garbage collector at work. (beware this
is allot of information) I have been very impressed with the garbage
collection with Sun JDK1.3x. I also use NT2000 but haven't monitored the
situation as closely in that environment.
Regards,
Craig