You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Matt Veitas <mv...@yahoo.com> on 2002/01/21 00:39:37 UTC

sessionClosing event???

I was looking through the code in StandardSession regarding removing an
attribute from the session. I was puzzled that the attributes were removed
and the event fired off...is there a reason for this?

What I am trying to do is to do some cleanup work on the object that was
bound to the session (doing some database stuff). Since the attributes in
the session are removed before the valueUnbound or sessionDestroyed events
are called, I can't do my clean up. Is there any way around this without
going in and changing the code?

I would like to propose additional an additional method such as a
sessionClosing() method so you can do some cleanup before it actually is
invalidated. What do people this about this?


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: sessionClosing event???

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Sun, 20 Jan 2002, Matt Veitas wrote:

> Date: Sun, 20 Jan 2002 18:39:37 -0500
> From: Matt Veitas <mv...@yahoo.com>
> Reply-To: Tomcat Developers List <to...@jakarta.apache.org>,
>      mveitas@yahoo.com
> To: tomcat-dev@jakarta.apache.org
> Subject: sessionClosing event???
>
> I was looking through the code in StandardSession regarding removing an
> attribute from the session. I was puzzled that the attributes were removed
> and the event fired off...is there a reason for this?
>

Servlet Specification, version 2.3, section 7.4:

    "The valueUnbound method must be called after the object
    is no longer available via the getAttribute method of the
    HttpSession interface"

In essence, this guarantees that no other simultaneous threads accessing
this session will be able to grab your object while you are doing your
cleanup processing.

> What I am trying to do is to do some cleanup work on the object that was
> bound to the session (doing some database stuff). Since the attributes in
> the session are removed before the valueUnbound or sessionDestroyed events
> are called, I can't do my clean up. Is there any way around this without
> going in and changing the code?
>

Why can't you do your cleanup in the valueUnbound method?  It's been in
the servlet API for exactly this reason since at least 2.0 days.  And, the
HttpSessionBindingEvent you receive has a reference to the session itself,
and the attribute name you were formerly bound under, so you can go clean
up related things as well.

> I would like to propose additional an additional method such as a
> sessionClosing() method so you can do some cleanup before it actually is
> invalidated. What do people this about this?
>

This would need to be added to the servlet spec to be generally useful --
the appropriate place to recommend it would be the spec feedback address:
<se...@eng.sun.com>.

Craig


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>