aspose file tools*
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
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: 4181
    
  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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cache Implementation with ReentrantReadWriteLock BUT how to lock upgrade??