reentrantreadwritelock

Java ReentrantReadWriteLocks - how to safely acquire write lock?

I am using in my code at the moment a ReentrantReadWriteLock to synchronize access over a tree-like structure. This structure is large, and read by many threads at once with occasional modifications to small parts of it - so it seems to fit the read-write idiom well. I understand that with this particular class, one cannot elevate a re...

File locking (read/write) in Java

I'm writing something to handle concurrent read/write requests to a database file. ReentrantReadWriteLock looks like a good match. If all threads access a shared RandomAccessFile object, do I need to worry about the file pointer with concurrent readers? Consider this example: import java.io.FileNotFoundException; import java.io.IOExc...

Documentation for java.util.concurrent.locks.ReentrantReadWriteLock

Disclaimer: I'm not very good at Java and just comparing read/writer locks between C# and Java to understand this topic better & decisions behind both implementations. There is JavaDoc about ReentrantReadWriteLock. It states the following about upgrade/downgrade for locks: Lock downgrading ... However, upgrading from a read lock to...

Is it a good practice to wrap ConcurrentHashMap read and write operations with ReentrantLock?

I think in the implementation of ConcurrentHashMap, ReentrantLock has already been used. So there is no need to use ReentrantLock for the access of a ConcurrentHashMap object. And that will only add more synchronization overhead. Any comments? ...