public class ReadWriteLock extends Object
Requests are first-in-first-out but Write request have priority over read requests - so it is possible for continuous write requests to completely deny read requests, but not for read requests to deny write requests.
Constructor and Description |
---|
ReadWriteLock() |
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the lock.
|
boolean |
isClosed()
Returns if the lock is closed.
|
boolean |
lock(boolean forWriting,
int timeout,
boolean allowInterrupt) |
void |
pauseWriting()
Only the writer holding the lock can call this.
|
boolean |
read()
This method requests a Read lock and does not return
until it has been satisfied or until the lock is closed.
|
boolean |
read(int timeout)
This method requests a Read lock and returns if the request
was granted or if the timeout expired or the lock was closed.
|
void |
resumeWriting()
Only the writer holding the lock can call this after a single
call to pauseWriting().
|
void |
unlock()
Release a read or write lock.
|
boolean |
write()
This method requests a Write lock and does not return
until it has been satisfied or until the lock is closed.
|
boolean |
write(int timeout)
This method requests a Write lock and returns if the request
was granted or if the timeout expired or the lock was closed.
|
public boolean isClosed()
public void close()
public final boolean lock(boolean forWriting, int timeout, boolean allowInterrupt) throws InterruptedException
InterruptedException
public final boolean read(int timeout)
timeout
- the time to wait.public final boolean read()
public final boolean write(int timeout)
timeout
- the time to wait.public final boolean write()
public final void unlock() throws IllegalThreadStateException
IllegalThreadStateException
public final void pauseWriting()
There cannot be nested calls of pauseWriting().
public final void resumeWriting()
If Readers did acquire the lock while writing was paused, this method will not return until they have all released the lock.