Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

WeakHashmap or TimerTask for stale sessions cleanup ?

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, the issue is about stale sessions.

Stale sessions - As we have the Weakhashmap data structure in jdk that cleans up unreferenced objects, though there is no regular specific time interval when it cleans up.
I looked at its implementation, it seem to clean up upon certain events such as calling size(), adding new entry etc., on the map.

What are the advantages of using this as opposed to timer. one less thing to do and addressing infinite locks by non-existing user sessions at the same time

Any comments ?
 
author and jackaroo
Posts: 12199
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Steve,

My personal view is that the instructions seem to indicate that I should be able to own a lock as long as I want. There is no indication of a timeout in the interface definition. There is no indication of a timeout anywhere else in the instructions.

So if you were to implement a timeout, you are introducing something that has not been asked for. Furthermore you will be specifying a time limit that other users may not be expecting, and there is no standard idea of what sort of timeout to put on it - in real life a decision on timeout values would either come about after discussion with the relevant parties (which we cant do) or be configurable (hmmm - we could end up with too many configurable options in our GUI if we are not careful).

So, if we are going to worry about stale sessions (which I don't believe we have to worry about), then I would prefer to do it in one of two ways:
  • Have some generic way of clearing stale locks within the Data class itself that will work no matter whether we have a Sockets based or an RMI based solution. WeakHashMap fits that description.
  • Have a protocol based solution (clean-up code in SocketException in a sockets based solution, or in Unreferenced.unreferenced() for an RMI based solution.
  • Both have their good and bad points. Sometimes the interface you have been provided by Sun makes one or the other problematic which can be the deciding factor

    Regards, Andrew
     
    You showed up just in time for the waffles! And this tiny ad:
    Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    reply
      Bookmark Topic Watch Topic
    • New Topic