Convenience implementation of a read/write lock based on GenericLock .
Reads are shared which means there can be any number of concurrent read
accesses allowed by this lock. Writes are exclusive. This means when there is
a write access no other access neither read nor write are allowed by this
lock. Additionally, writes are preferred over reads in order to avoid starvation. The idea
is that there are many readers, but few writers and if things work out bad the writer would
never be served at all. That's why it is preferred.
Calls to both acquireRead(Object, long) and
acquireWrite(Object, long) are blocking and reentrant. Blocking
means they will wait if they can not acquire the descired access, reentrant means that a lock
request by a specific owner will always be compatible with other accesses on this lock by the
same owner. E.g. if you already have a lock for writing and you try to acquire write access
again you will not be blocked by this first lock, while others of course will be. This is the
natural way you already know from Java monitors and synchronized blocks.
Reads are shared which means there can be any number of concurrent read accesses allowed by this lock. Writes are exclusive. This means when there is a write access no other access neither read nor write are allowed by this lock. Additionally, writes are preferred over reads in order to avoid starvation. The idea is that there are many readers, but few writers and if things work out bad the writer would never be served at all. That's why it is preferred.
Calls to both acquireRead(Object, long) and acquireWrite(Object, long) are blocking and reentrant. Blocking means they will wait if they can not acquire the descired access, reentrant means that a lock request by a specific owner will always be compatible with other accesses on this lock by the same owner. E.g. if you already have a lock for writing and you try to acquire write access again you will not be blocked by this first lock, while others of course will be. This is the natural way you already know from Java monitors and synchronized blocks.