|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.sun.jts.CosTransactions.RWLock
public class RWLock
A RWLock provides concurrency control for multiple readers single writer access patterns. This lock can provide access to multiple reader threads simultaneously as long as there are no writer threads. Once a writer thread gains access to the instance locked by a RWLock, all the reader threads wait till the writer completes accessing the instance in question.
A RWLock is extremely useful in scenarios where there are lots more readers and very few writers to a data structure. Also if the read operation by the reader thread could take significant amount of time (binary search etc.)
The usage of Lock can be see as under:
public class MyBTree {
private RWLock lock = new Lock();
.....
.....
public Object find(Object o) {
try {
lock.acquireReadLock();
....perform complex search to get the Object ...
return result;
} finally {
lock.releaseReadLock();
}
}
public void insert(Object o) {
try {
lock.acquireWriteLock();
....perform complex operation to insert object ...
} finally {
lock.releaseWriteLock();
}
}
}
| Constructor Summary | |
|---|---|
RWLock()
|
|
| Method Summary | |
|---|---|
void |
acquireReadLock()
This method is used to acquire a read lock. |
void |
acquireWriteLock()
This method is used to acquire a write lock. |
boolean |
isWriteLocked()
isWriteLocked returns true if the RWLock is in a write locked state. |
void |
releaseReadLock()
This method is used to release a read lock. |
void |
releaseWriteLock()
This method is used to release a write lock. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public RWLock()
| Method Detail |
|---|
public void acquireReadLock()
public void acquireWriteLock()
public boolean isWriteLocked()
public void releaseReadLock()
public void releaseWriteLock()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||