aspose file tools*
The moose likes Servlets and the fly likes A doubt about sessionDestroyed method in HttpSessionListener Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "A doubt about sessionDestroyed method in HttpSessionListener" Watch "A doubt about sessionDestroyed method in HttpSessionListener" New topic
Author

A doubt about sessionDestroyed method in HttpSessionListener

Parthiban Malayandi
Ranch Hand

Joined: Apr 15, 2008
Posts: 70
Hi all,

I studied that sessionDestroyed method will be fired when a session is about to invalidate .

To understand this created a program in which I set a session's maximum inactive time as five seconds using setMaxInactiveInterval method of HttpSession

as


and I expect sessionDestroyed method will be invoked before that seconds(5 seconds) which I set using setMaxInactiveInterval method but it did not .

sessionDestroyed method invoked after a minute .

Why is it so ? .I'm using Tomcat 5.5.27 (servlet 2.4 version)

Thanks in advance

Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30973
    
159

Parthiban,
As I recall setting the max inactive time allows the servlet container to invalidate the session after that. Rather than being a promise to invalidate it exactly that. What you are seeing is consistent with my memories of how this works.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Parthiban Malayandi
Ranch Hand

Joined: Apr 15, 2008
Posts: 70
Jeanne Boyarsky wrote:Parthiban,
As I recall setting the max inactive time allows the servlet container to invalidate the session after that. Rather than being a promise to invalidate it exactly that. What you are seeing is consistent with my memories of how this works.


Hi Jeanne ,

Thanks for your reply but what confuses me is the servlet specification:
It says that sessionDestroyed method will be invoked before the session invalidates which is what confuses me

Here's the extract from the specification

SRV.1.6.1 HttpSessionListener.sessionDestroyed
==============================================

In the previous versions of the specification, this method was defined as:
Notification that a session was invalidated.
As of Version 2.4, this method is changed to:

Notification that a session is about to be invalidated

so that it notifies before the session invalidation. If the code assumed the previous
behavior, it must be modified to match the new behavior.

Please clarify me.
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3855

Parthiban Mahiby wrote:SRV.1.6.1 HttpSessionListener.sessionDestroyed
==============================================
In the previous versions of the specification, this method was defined as:
Notification that a session was invalidated.
As of Version 2.4, this method is changed to:

Notification that a session is about to be invalidated

so that it notifies before the session invalidation. If the code assumed the previous
behavior, it must be modified to match the new behavior.
Please clarify me.


According to the spec Yes, If the container running the code conforms to the Servlet 2.4 spec.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
ahmed yehia
Ranch Hand

Joined: Apr 22, 2006
Posts: 424
Notification that a session is about to be invalidated

I think this can further be clarified in that session scoped attributes are still valid if called from within sessionDestroyed().
Hence at this point the session is still valid, but about to be invalidated.
Eduardo Bueno
Ranch Hand

Joined: Jun 04, 2009
Posts: 155
To receive notification events, the implementation class must be configured in the deployment descriptor for the web application.

From J2EE 5 documentation. How did you find out that sessionDestroyed method was invoked after a minute?
Parthiban Malayandi
Ranch Hand

Joined: Apr 15, 2008
Posts: 70
Eduardo Bueno wrote:
To receive notification events, the implementation class must be configured in the deployment descriptor for the web application.

From J2EE 5 documentation. How did you find out that sessionDestroyed method was invoked after a minute?


Hi Eduardo,

Thanks for your reply I had written a Listener class to find that.
Parthiban Malayandi
Ranch Hand

Joined: Apr 15, 2008
Posts: 70
Hi all,

Thanks for all your replies.which helpmed me to get it.
 
 
subject: A doubt about sessionDestroyed method in HttpSessionListener