• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

session timeout and finally method

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67650
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Done.

Thank you both *very* much...

Amy
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic