Riz,

> I noticed that when I restart the tomcat server the "Active Sessions"
> count for one of the applications remains the same as it was before
> the server was shut down. Does this make sense?

When you shut down Tomcat, I believe the default is to write session
information out to a saved-sessions file. When you start Tomcat back up,
it reads this file so that any active sessions can be maintained across
the restart.

It is intended to be a nice feature so you don't forcibly log people out
of your application in the event of a restart.

You are probably not experiencing this same phenomenon in your /other/
application for one of three reasons:

1. You don't use sessions.
2. Your sessions contain objects that are non-serializable.
3. Objects in your session are serializable, but you lack
   the correct methods in those classes to read the object
   from storage.

Tomcat uses basic Java serialization to write the sessions to the
session-save file. If you have a non-serializable objects, they cannot
be serialized.

When reading the objects back into memory, it's still possible that a
session object's class is inappropriate for de-serialization. For
example, I have a "User" class that fails this all the time:

java.io.InvalidClassException: mypackage.User; no valid constructor

It I have a look at my class, I see this definition:

public class User
    extends AbstractIdentifiable
    implements Serializable

My class implements Serializable, and extends from:

public abstract class AbstractIdentifiable
    implements Identifiable

My "Identifiable" interface does not extend anything, and
AbstractIdentifiable does not implement Serializable. Since I don't have
any special serialization code in User, my User class is not
serializable, either, since its parent class is not serializable.

I get exceptions when I start my application, and the sessions die
because they couldn't be read from the session store.

Session persistence seems to be enabled by default, which is odd. I
removed the declaration for <Manager className="...PersistentManager">
from my <Context> definition, and the sessions were still persisted. I
was able to turn it off completely using this configuration:

          <Manager className="org.apache.catalina.session.PersistentManager"
              debug="99"
              saveOnRestart="false"
              maxActiveSessions="-1"
              minIdleSwap="-1"
              maxIdleSwap="-1"
              maxIdleBackup="-1">
                <Store className="org.apache.catalina.session.FileStore"/>
          </Manager>

I should note that I'm using Tomcat 4.1.31, so if you are using a
different version, things might be slightly different.

> I should add that we are using mod_jk to forward requests from apache
> web server to tomcat.

mod_jk is irrelevant, here.

Hope that helps.

-chris


Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to