|
|||||||||
| Home >> All >> org >> ematgine >> utils >> [ concurrent overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.ematgine.utils.concurrent
Interface ReadWriteLock

- All Known Implementing Classes:
- FIFOReadWriteLock, 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.
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()
}
}
}
| 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
|
|||||||||
| Home >> All >> org >> ematgine >> utils >> [ concurrent overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC