Class ReentrantWriterPreferenceReadWriteLock

  • All Implemented Interfaces:

    public class ReentrantWriterPreferenceReadWriteLock
    extends WriterPreferenceReadWriteLock
    A writer-preference ReadWriteLock that allows both readers and writers to reacquire read or write locks in the style of a ReentrantLock. Readers are not allowed until all write locks held by the writing thread have been released. Among other applications, reentrancy can be useful when write locks are held during calls or callbacks to methods that perform reads under read locks.

    Sample usage . Here is a code sketch showing how to exploit reentrancy to perform lock downgrading after updating a cache:

      class CachedData {
        Object data;
        volatile boolean cacheValid;
        ReentrantWriterPreferenceReadWriteLock rwl = ...
        void processCachedData() {
          if (!cacheValid) {
             // upgrade lock:
             rwl.readLock().release();   // must release first to obtain writelock
             if (!cacheValid) { // recheck
               data = ...
               cacheValid = true;
             // downgrade lock
             rwl.readLock().acquire();  // reacquire read without giving up lock
             rwl.writeLock().release(); // release write, still hold read

    [ Introduction to this package. ]

    MicroStrategy Web 7.3.1 or earlier