问题描述:

Should values kept in Tomcat Session be set to null when session is being destroyed?

Or they are automatically destroyed?

We had a problem with multiple .ser files in tomcat folder. Could that be because we do not set values kept in session to null after using them ?

网友答案:

Should values kept in Tomcat Session be set to null when session is being destroyed? Or they are automatically destroyed?

When a session get invalidated, its attributes will just be dereferenced. When they aren't referenced by any other object, then they will be eligible for GC. Once GC runs, then they will be destroyed, yes.

We had a problem with multiple .ser files in tomcat folder. Could that be because we do not set values kept in session to null after using them ?

No. This sounds like as if Tomcat crashed during startup or shutdown. I'd read the logs.

网友答案:

When session is destroyed, any contained objects in the session are also destroyed (i.e. garbage collected if the session is the only one holding on to them). You don't have to set them to null after use.

Tomcat has a feature of serializing sessions on shutdown and trying to re-activate them on start up, called restart persistance. Are you referring to this? If it causes problems for you, it can be deactivated (see the attributes of the standard manager implementation in the same document).

相关阅读:
Top