Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cache Implementation with ReentrantReadWriteLock BUT how to lock upgrade??

 
Ulas Ergin
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,
I have a question about lock upgrading.Specifically what bothers me is between readlock.unlock() and following writelock.lock()...
I am providing a nearly complete implementation for a sample cache.I just omitted actual loading of cached data from database.

I appreciate if you can review the code and share your thoughts. I tried to express my concern in the java comments .

 
Steve Luke
Bartender
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I think you will have to check again, but the check doesn't have to be expensive, it is just a re-use of the putIfAbsent call:

 
Ulas Ergin
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes,I have infact implemented the recheck...but i am looking for an elegant solution
 
Ulas Ergin
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
any other ideas?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic