Interface ReadWriteLock

  • All Known Implementing Classes:
    ReadWriteLockLogWrapper, ReentrantWriterPreferenceReadWriteLock, WriterPreferenceReadWriteLock

    public interface ReadWriteLock
    ReadWriteLocks maintain a pair of associated locks. The readLock may be held simultanously by multiple reader threads, so long as there are no writers. The writeLock is exclusive. ReadWrite locks are generally preferable to plain Sync locks or synchronized methods in cases where:
    • The methods in a class can be cleanly separated into those that only access (read) data vs those that modify (write).
    • Target applications generally have more readers than writers.
    • The methods are relatively time-consuming (as a rough rule of thumb, exceed more than a hundred instructions), so it pays to introduce a bit more overhead associated with ReadWrite locks compared to simple synchronized methods etc in order to allow concurrency among reader threads.
    Different implementation classes differ in policies surrounding which threads to prefer when there is contention. By far, the most commonly useful policy is WriterPreferenceReadWriteLock. The other implementations are targeted for less common, niche applications.

    Standard usage:

     class X {
         ReadWriteLock rw;
         // ...
        public void read() throws InterruptedException { 
          try {
            // ... do the read
          finally {
        public void write() throws InterruptedException { 
          try {
            // ... do the write
          finally {
    MicroStrategy Web 7.3.1 or earlier
    See Also:
    [ Introduction to this package. ]
    • Method Detail

      • readLock

        Sync readLock()
        get the readLock *
      • writeLock

        Sync writeLock()
        get the writeLock *