• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

session timeout and finally method

 
A Saari
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anyone know ... when the web server times out a session I'm assuming all instances created by that session end up being garbage collected at some point - right? And when that happens the finally method gets called for each instance - right?

I have a static list containing locked projects (i.e. locked for edit in some browser somewhere) and if someone gets up and walks away I need to release that lock (in the finally method right now).

Will the above work correctly?

Does someone know of a more elegant soln?

Thanks,
Amy
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would be better, in my opinion, to use a session listener to react to a session going out of scope rather than relying on garbage collection.
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

when the web server times out a session I'm assuming all instances created by that session end up being garbage collected at some point - right?


It would be more appropriate to say objects bound to session scope are eligible for GC once the user session times-out. Objects are NOT created by session, objects are bound to session.



And when that happens the finally method gets called for each instance - right?


We don't no when GC runs so we don't know when finally method will be executed and also the order is also NOT guaranteed.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also note that the objects may have another reference somewhere - possibly in a collection - thus preventing them from ever being GCed.
So - like Bear said - use one of the listener interfaces to ensure correct handling. For example, have the object that holds the lock implement HttpSessionBindingListener, then the valueUnbound method is guaranteed to be called when the session is invalidated.
Bill
 
A Saari
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Done.

Thank you both *very* much...

Amy
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic