Forums Register Login

A doubt about sessionDestroyed method in HttpSessionListener

+Pie Number of slices to send: Send
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

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
 

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?
+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
Hi all,

Thanks for all your replies.which helpmed me to get it.
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 3267 times.
Similar Threads
question on destroying a session
how to use session?
How to use setMaxInactiveInterval()
How to prompt user that session is going to time out ?
SessionListener?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 06:56:24.