• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Lock Manager & SoftReference?

 
Bob Reeves
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All:
My assignment is the uRLyBird Hotel Booking application. I'm using a LockManager to provide cookie and synchronization control. One issue with the LockManager is deleting the Locks when they're no longer in use. I'm using the direct approach to the removal problem: reference counting.
But, I keep thinking that SoftReference garbage collection should assist here. I've gobbled together a scheme that seems workable: when the lock is actually in use, store a reference to it in the LockManager. It looks like SoftReference should work as cobbled (no I didn't try). This approach, of course, has considerable overhead with the new reference Collection.
Anyone thought of a clean method to garbage collect Locks in the Lock Manager?
Tx
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your question confuses me. I noticed no one had replied, so I came in and checked it out. Maybe you have already gotten your answer.
But what are you actually asking? If a client calls lock and it goes to the LockManager, then the client will call unlock and that goes to the LockManager which removes the lock. Is there something beyond that that I am missing?
If you want to know about what happens if a client crashes and it still have a lock in the LockManager, then look at the Unreferenced interface.
Mark
 
Bob Reeves
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark:
I asked this question because basically I'm lazy, and don't want to do more work than necessary. I thought I saw a labor saving possibility in the java.lang.ref package: SoftReference, WeakReference, and I think there are Strong and PhantomReference types.
These references provide hints to the garbage system that certain objects may be reclaimed. (Hey, you mean I just plunk down a SoftReference lock into the LockManager, and the garbage system can reclaim it when auspicious? Looks good to me!)
The algoritm that is used to reclaim SoftReferences seems adaptable to the LockManager, except for maintaing the object while only the cookie holder is reserving it (i.e., you need a reference to the object to cause the garbage collector to defer collection when the lock is assigned a cookie). So, I was thinking -- if there's a friendly way to get this reference, Viola, free lock reclamation! Wow!
My assignment is past the point where I could use this type approach, but I think the concept is still interesting. Just not too clear on how it sould be applied.
Tx
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unfortunately I am not clear how that could work for the assignment. It does sound interesting though.
One thing about the assignment that I always follow, is to use a standard, already built classes that everyone mostly knows about, or can find and figure out quickly. The SoftReference seems to me a solution that is already built, but not commonly used. So I would refrain from using it, simply to make the application simpler for a junior programmer to understand.
Mark
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bob
You might want to look at this thread. There is some discussion on using WeakHashMaps for locks in it.
Regards, Andrew
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic