Forums Register Login

Question on session expiration

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
Have you checked out javax.servlet.http.HttpSessionBindingListener?
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
I do some of my very best work in water. Like this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 572 times.
Similar Threads
How to create singleton in clustered environment?
Singleton Factory Object
When Singleton class get garbage collected?
garbage collection
Singlton pattern and Garbage collection
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 05:08:48.