Package marauroa.server
Class RWLock
java.lang.Object
marauroa.server.RWLock
This class is a Reader/Writters lock A Reader Writer Lock is a
synchronization mechanism allowing access to data.
It allows multiple threads to read the data simultaneously, but only one thread at a time to update it.
It allows multiple threads to read the data simultaneously, but only one thread at a time to update it.
Controlling concurrent access to a shared, mutable resource is a classic problem. Clients request, and later release, either read-only or read-write access to the resource. To preserve consistency but minimize waiting, one usually wishes to allow either any number of readers or a single writer, but not both, to have access at any one time.
While a thread is updating, no other thread can read the data. The name is misleading. It may cause you to think there are two locks; in reality there is a single lock that restricts both reading and writing.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
This releases the lock for both readers and writers.void
Request a reader lock.
Readers can obtain a lock as long as there is no writer.void
Request a Writers lock.
-
Constructor Details
-
RWLock
public RWLock()Constructor
-
-
Method Details
-
requestReadLock
public void requestReadLock()Request a reader lock.
Readers can obtain a lock as long as there is no writer. -
requestWriteLock
public void requestWriteLock()Request a Writers lock. A writer can obtain the lock as long as there are no more writers nor readers using the lock. -
releaseLock
public void releaseLock()This releases the lock for both readers and writers.
-