This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes HTTP Session listener and session destroyed call Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "HTTP Session listener and session destroyed call" Watch "HTTP Session listener and session destroyed call" New topic
Author

HTTP Session listener and session destroyed call

Monmohan Singh
Ranch Hand

Joined: Aug 02, 2002
Posts: 82
we need to implement an edit lock on some of our records so that they can't be simultaneously edited by two users.
Also we need to clean up the lock when the user time out happens.
We thought of implementing this using an HTTPSessionListener but the servlet 2.3 API suggests that the sessionDestroyed() is called after the session is destroyed. Then we have no way to decide what and which user to cleanup??
Looks like writing our own deamon thread is only possibility
Any thoughts on this will be helpful - posted this on servlet forum but no answers
Mallik Hiremath
Ranch Hand

Joined: Oct 20, 2002
Posts: 46
Assuming that you are talking about the HttpSession, you can use the sessionDestroyed() method and implement your functionality, because the sessionDestroyed looks like its being called just before the session is invalidated, from with in this method you can get hold of the HttpSessionEvent from the session event you can get the Session Object and get those values which you have stored in the Session
V 2.3 API says:
sessionDestroyed(HttpSessionEvent se)
public void sessionDestroyed(HttpSessionEvent se)Notification that a session is about to be invalidated.
Parameters:
se - the notification event
-Mallik
Monmohan Singh
Ranch Hand

Joined: Aug 02, 2002
Posts: 82
Actually I also though the same but
According to http://developer.java.sun.com/developer/EJTechTips/2003/tt0626.html
�javax.servlet.http.HttpSessionListener.
The methods in this interface are called when an HTTP session is created or destroyed. Whether the call to the method occurs before or after the session is invalidated, depends on which specification version (2.3 or 2.4) is being used.
It's worthwhile to verify the behavior of the platform implementation you are using if your application behavior depends on this detail.�
Mallik Hiremath
Ranch Hand

Joined: Oct 20, 2002
Posts: 46
Yes, You are correct
In API 2.3 the sessionDestroyed() method is called just after the Session was invalidated
In Servlet API 2.4 the sessionDestroyed() method is called just before the Session is getting invalidated (means you can still get a reference to Session )
I don't know which API you are or planning to using!!

-Mallik
Christian Ebage
Ranch Hand

Joined: Aug 29, 2002
Posts: 47

we need to implement an edit lock on some of our records so that they can't be simultaneously edited by two users.Also we need to clean up the lock when the user time out happens.We thought of implementing this using an HTTPSessionListener but the servlet 2.3 API suggests that the sessionDestroyed() is called after the session is destroyed. Then we have no way to decide what and which user to cleanup?? Looks like writing our own deamon thread is only possibility Any thoughts on this will be helpful

Have you considered wraping the current user's session id in a class then implement the HttpSessionBinding Interface? When the user logs in, you could wrap this class in the user's session, instead of the user's id itself directly in the session.When the session invalidates, the container calls the valueUnbound() method on the wrapper class. This gives you the chance to cleanup the current user. Hope this helps
Ebage
SCJP
SCWCD
SCEA
[ September 21, 2003: Message edited by: Christian Ebage ]
Monmohan Singh
Ranch Hand

Joined: Aug 02, 2002
Posts: 82
thanks, we will try this
Christian Ebage
Ranch Hand

Joined: Aug 29, 2002
Posts: 47
Sorry, I meant the HttpSessionBindingListener interface. There is nothing like HttpSessionBinding interface.
Ebage
SCJP
SCWCD
SCEA
[ September 22, 2003: Message edited by: Christian Ebage ]
Monmohan Singh
Ranch Hand

Joined: Aug 02, 2002
Posts: 82
I understood that
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HTTP Session listener and session destroyed call
 
Similar Threads
servlets
HTTP Session listener and session destroyed call
session management -session not destroying automatically
Form Bean - Session Scope
Stateful session EJB lock timeouts - WKS 6.1