This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Threads and Synchronization and the fly likes Cache Implementation with ReentrantReadWriteLock  BUT how to lock upgrade?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Cache Implementation with ReentrantReadWriteLock  BUT how to lock upgrade??" Watch "Cache Implementation with ReentrantReadWriteLock  BUT how to lock upgrade??" New topic
Author

Cache Implementation with ReentrantReadWriteLock BUT how to lock upgrade??

Ulas Ergin
Ranch Hand

Joined: Oct 10, 2002
Posts: 77
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

Joined: Jan 28, 2003
Posts: 4167
    
  21

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:



Steve
Ulas Ergin
Ranch Hand

Joined: Oct 10, 2002
Posts: 77
Yes,I have infact implemented the recheck...but i am looking for an elegant solution
Ulas Ergin
Ranch Hand

Joined: Oct 10, 2002
Posts: 77
any other ideas?
 
wood burning stoves
 
subject: Cache Implementation with ReentrantReadWriteLock BUT how to lock upgrade??
 
Similar Threads
Concurrency issue with create(...)/createRecord(...) [URLyBird]
Lock and Search
recordNumbersLock - how is it associated to recordNumbers map?
Threads and database approach question
ReentrantReadWriteLock's lock mechanism