Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A doubt about sessionDestroyed method in HttpSessionListener

 
Parthiban Malayandi
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34410
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Parthiban Malayandi
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
ahmed yehia
Ranch Hand
Posts: 424
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Thanks for all your replies.which helpmed me to get it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic