Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Too much memory for record locking?

 
Dushy Inguva
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
Im using a map based implementation for record locking. Right now, im using a HashMap. But, im concerned that i might have to use a WeakHashMap.
The reason is, if the number of records are more, each creates an object in the map. Even if no thread is waiting/holding the record lock, it is never freed.
Do you think it is necessary for me to use a WeakHashMap? (i will have to take care of holding a strong reference as long as the record is locked)
Dushy
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dushy,
Why can't your unlock() method remove the object from the Map?
Why are you worried about how much memory this is taking up? How many records would you have to have locked in order for the memory to become an issue?
Regards, Andrew
 
Dushy Inguva
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Andrew,
Thanks for your fast reply.
Yes my unlock could see if there are no threads waiting to obtain the lock and remove it. The problem is, I am afraid that might increase the number of objects being created and destroyed.
Well, for the project, this might not be a problem, but since Sun is going to look at the design decisions as well, i am not sure which approach to take.
Here are the possible approaches that i am looking at:
1. Just store them in a HashMap and not do any memory freeing
2. Store them in a HashMap and build intelligent unlock method
3. Store them in a WeakHashMap and leave it on the gc. (Ill have to make my lock restore a strong reference to the object and unlock remove it)
Could you help me choose...
Thanks
Dushy
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dushy,
I just want to check my understanding: you are storing an object in the map for each record thats locked, and any waiting clients will wait on that object that is within the map. Is that correct?
Regarding leaving the lock object in the map: how often is it likely to be called during the record's life cycle? Once you answer that, you might find yourself leaning towards one of those three options you mentioned.
Regards, Andrew
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic