Arpit Purohit wrote:
I have Object added to a Session which makes connection to another server(like Database-Connection or Socket).
Ouch, that's really a bad practice. Never do that.
You should acquire AND close expensive
JDBC resources as soon as possible and in the shortest possible scope. To improve performance you can make use of connection pooling, but still then, you should acquire and close them in the shortest possible scope.
I use to close it explicitly when user logs out. But How to do this when user close the browser?
Do the Session Invalidating due to session timeout in turn destroys all the objects it holds?
And if the answer is Yes then what about the connection established by object with another server?
How that connection can to be closed explicitly in such condition?
Regards
Arpit Purohit
Although the answer is indeed Yes, when the session expires, it will trash all bound objects. But in this case it is irrelevant, you shouldn't even think about storing expensive resources in a session. It makes your application unreliable as it may crash at unpredicted moments due to a connection timeout.