org.sape.carbon.core.util.thread
Interface ReadWriteLock

All Known Implementing Classes:
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:

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 {
     rw.readLock().acquire();
     try {
       // ... do the read
     }
     finally {
       rw.readlock().release()
     }
   }


   public void write() throws InterruptedException {
     rw.writeLock().acquire();
     try {
       // ... do the write
     }
     finally {
       rw.writelock().release()
     }
   }
 }
 

[ Introduction to this package. ]

Since:
carbon 2.0
Version:
$Revision: 1.3 $($Author: dvoet $ / $Date: 2003/05/05 21:21:24 $)
Author:
Greg Hinkle, March 2003

Method Summary
 Sync readLock()
          get the readLock
 Sync writeLock()
          get the writeLock
 

Method Detail

readLock

public Sync readLock()
get the readLock


writeLock

public Sync writeLock()
get the writeLock



Copyright 1999-2003 Sapient Corporation. All Rights Reserved.