• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question on session expiration

 
Dhiren Joshi
Ranch Hand
Posts: 463
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone,
I have singleton where I am storing an object in a hashtable against sessionid as a key.
My question is if the session is invalidated will the object be garbage collected by the JVM ?
If not is there a way I can store the object per session in the singleton (The object is large so can not be stored in the session for performance issues)such that it can be eligible for garbage collection when a session expires.
We dont have control over the signout or invalidation of a session. The appServer handles it at its end.
Thanks
Dhiren
 
Terry Mullett
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you checked out javax.servlet.http.HttpSessionBindingListener?
 
Dhiren Joshi
Ranch Hand
Posts: 463
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Terry,
I checked it out.
valueBound(HttpSessionBindingEvent)
Notifies the listener that it is being bound into a session.
valueUnbound(HttpSessionBindingEvent)
Notifies the listener that it is being unbound from a session


I dont want to bind into a session. For performance reasons I cant use session to store the object.

What I am trying to do is store it in a singleton in a hashmap.
Now I need to make the key something session dependent such that if my session expires, the key reference is nullified so that the key value pair can be eligible for garabage collection.

Does this interface help here...
Any one.
Thanks
Dhiren
 
Terry Mullett
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could store a lighter-weight object in the session, a sentinel, that implements the listener interface and can identify the object being stored in the singleton. When the session expires and the sentinel is unbound, it's valueUnbound callback method can alert the singleton to get rid of your heavyweight object. A little roundabout maybe, just the first thing that occurred to me.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic