Forums Register Login

valueUnbound method of HttpSessionBindindListener

+Pie Number of slices to send: Send
When is the valueUnbound method of HttpSessionBindindListener called and what is the purpose of using it.can someone give example

thnx in advance
+Pie Number of slices to send: Send
Hi N Chaurasia,

As per my knowledge, the method valueUnbound is called exactly before removal of the object from the session. If you've a class which implements HttpSessionBindingListener, while removing an object of that class from the session, valueUnbound method will be called. So, this is from object to object i.e. one can track for a particular object and while binding or unbinding, allocate resources or deallocate the same.

There is another listener you may aware of i.e. HttpSessionAttributeLisener by which the tracking of all the sessions' attributes is possible. One more point to note. There is no need to configure for HttpSessionBindingListener. But for HttpSessionAttributeListener it is mendatory to do so.
[ October 03, 2005: Message edited by: Bimal Patel ]
+Pie Number of slices to send: Send
Hi Bimal,
I have another query. You said : one can track for a particular object and while binding or unbinding, allocate resources or deallocate the same.


Is there any specific advantage to deallocate resource after/before the object if unbound from the session. We could be it before or after. Will it make any difference.
+Pie Number of slices to send: Send
Hi N Charasia,

Well, one thing is for sure that whenever that object is being garbage collected, objects inside that will also be garbage collected. And in that way, from the first sight, we don't need to write those things in valueUnbound method. Actually I've given you only one example. There may be many other things to be performed like if you are writing to a file IO, you better need to close the stream after flushing. Right? So, such kind of operation you can perform in valueUnbound method. And in valueBound method, you may intialise certain objects with proper parameters. One more example is a JDBC connection object. Or there may be some session specific things, I can't specify because I've not used HttpSessionBindingListener, you can perform in valueBound and valueUnbound methods.

I think there are very few instances when you need to use this listener. But if you really want to track whether a particular object is removed from the session, you can do that with this listener.
Willie Smits increased rainfall 25% in three years by planting trees. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 592 times.
Similar Threads
valueUnbound - when called?
Detection of session timeout
Trapping Session timeout in JSP
HOW WILL I KNOW THAT THE BROWSER IS CLOSED?
How to Execute Session Destroying code in jsp
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 17:15:30.